[Request]Help, Tut to send keystroke un-active program

Posts 13 of 3 · Page 1 of 1
[Request]Help, Tut to send keystroke un-active program
Can anyone help me find a TUT that would help me make a program that sends keystrokes to an unactive program? I just need to send one keystroke(F1) to a program every 5 secs.
i think the code is
Code:
 SendKeys.Send("{F1}")
Correct me if i am wrong
You need to learn SystemWide Hotkeys and Virtual Keys, MSDN has about 5 articles (or more) on this.

In the mean time here is a introductory, If I get a chance I will right a [TUT]
in the mean time, this is not a tut, just a starting point to help you make a program with System Wide Hot Keys


Register System Wide HotKeys

Note:By using P/Invoke you can call Windows API to register a system-wide hot key and have it go to your form.


Declare the API

Note: this goes in the top most part of your code

Code:
Imports System.Runtime.InteropServices
Now we need to create two shared functions

Code:
Private Shared Function RegisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vlc As Integer) As Boolean
    End Function
Code:
 Private Shared Function UnregisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer) As Boolean
    End Function
3 parameters used for hot keys

Note: Definitions paraphrased from Wiki

Quote Originally Posted by Wiki

hWnd. = used to specify a handle to the window that should receive message.

id. = registers your hotkey with a id number using this parameter.

vlc. used to provide a virtual key for the hot key.

You will now to declare constants the code is as follows

Code:
Const "Constant Name" As Integer = "Hex Value"
Note: Remove quotes

Here is a list of VK's

Code:
VK_CANCEL	03	Control-break processing
VK_BACK	08	BACKSPACE key
VK_TAB	09	TAB key
VK_CLEAR	0C	CLEAR key
VK_RETURN	0D	ENTER key
VK_SHIFT	10	SHIFT key
VK_MENU	12	ALT key
VK_PAUSE	13	PAUSE key
VK_ESCAPE	1B	ESC key
VK_SPACE	20	SPACEBAR
VK_PRIOR	21	PAGE UP key
VK_NEXT	22	PAGE DOWN key
VK_END	23	END key
VK_HOME	24	HOME key
VK_LEFT	25	LEFT ARROW key
VK_UP	26	UP ARROW key
VK_RIGHT	27	RIGHT ARROW key
VK_DOWN	28	DOWN ARROW key
VK_SELECT	29	SELECT key
VK_PRINT	2A	PRINT key
VK_INSERT	2D	INS key
VK_DELETE	2E	DEL key
VK_HELP	2F	HELP key
Code:
VK_F1	70	F1 key
VK_F2	71	F2 key
VK_F3	72	F3 key
VK_F4	73	F4 key
VK_F5	74	F5 key
VK_F6	75	F6 key
VK_F7	76	F7 key
VK_F8	77	F8 key
VK_F9	78	F9 key
VK_F10	79	F10 key
VK_F11	7A	F11 key
VK_F12	7B	F12 key
VK_F13	7C	F13 key
VK_F14	7D	F14 key
VK_F15	7E	F15 key
VK_F16	7F	F16 key
VK_F17	80H	F17 key
VK_F18	81H	F18 key
VK_F19	82H	F19 key
VK_F20	83H	F20 key
VK_F21	84H	F21 key
VK_F22	85H	F22 key
VK_F23	86H	F23 key
VK_F24	87H	F24 key
MSDN offers a full list

So for a system wide hotkey for f1 you would do

Code:
Const VK_F1 As Integer = &70
Posts 13 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?