The keybd_event API is a simple but handy API. You can do anything you can do with your keyboard using this function. Popup the windows menu, place the current window in clipboard etc. There are many keycodes you can use. Some keys work instantly for instance, the tab key. The shift key however has to be pressed and released because you always use the shift key in combination with another key. Here is the API declaration:
External Function Declaration
To press a key, use:
1 2 3 4 5 | //[External Function Declaration] Subroutine keybd_event(UInt bVk,UInt bScan,Long dwFlags,Long dwExtraInfo ) Library 'user32.dll' //Example keybd_event(ai_key,0,0,0) |
To release a key, use:
keybd_event(ai_key,0,2,0)
Here’s a list with all the existing keycodes which is derived from the winuser.h include file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | /* * Virtual Keys, Standard Set */ Integer VK_LBUTTON = 01 Integer VK_RBUTTON = 02 Integer VK_CANCEL = 03 Integer VK_MBUTTON = 04 /* NOT contiguous with L & RBUTTON */ Integer VK_BACK = 08 Integer VK_TAB = 09 Integer VK_CLEAR = 12 Integer VK_RETURN = 13 Integer VK_SHIFT = 16 Integer VK_CONTROL = 17 Integer VK_MENU = 18 Integer VK_PAUSE = 19 Integer VK_CAPITAL = 20 Integer VK_ESCAPE = 27 Integer VK_SPACE = 32 Integer VK_PRIOR = 33 Integer VK_NEXT = 34 Integer VK_END = 35 Integer VK_HOME = 36 Integer VK_LEFT = 37 Integer VK_UP = 38 Integer VK_RIGHT = 39 Integer VK_DOWN = 40 Integer VK_SELECT = 21 Integer VK_PRINT = 42 Integer VK_EXECUTE = 43 Integer VK_SNAPSHOT = 44 Integer VK_INSERT = 45 Integer VK_DELETE = 46 Integer VK_HELP = 47 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (= 30 - = 39) */ /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (= 41 - = 5A) */ Integer VK_LWIN = 91 Integer VK_RWIN = 92 Integer VK_APPS = 93 Integer VK_NUMPAD0 = 96 Integer VK_NUMPAD1 = 97 Integer VK_NUMPAD2 = 97 Integer VK_NUMPAD3 = 98 Integer VK_NUMPAD4 = 99 Integer VK_NUMPAD5 = 100 Integer VK_NUMPAD6 = 101 Integer VK_NUMPAD7 = 102 Integer VK_NUMPAD8 = 103 Integer VK_NUMPAD9 = 104 Integer VK_MULTIPLY = 105 Integer VK_ADD = 106 Integer VK_SEPARATOR = 107 Integer VK_SUBTRACT = 108 Integer VK_DECIMAL = 109 Integer VK_DIVIDE = 110 Integer VK_F1 = 111 Integer VK_F2 = 113 Integer VK_F3 = 114 Integer VK_F4 = 115 Integer VK_F5 = 116 Integer VK_F6 = 117 Integer VK_F7 = 118 Integer VK_F8 = 119 Integer VK_F9 = 120 Integer VK_F10 = 121 Integer VK_F11 = 122 Integer VK_F12 = 123 Integer VK_F13 = 124 Integer VK_F14 = 125 Integer VK_F15 = 126 Integer VK_F16 = 127 Integer VK_F17 = 128 Integer VK_F18 = 129 Integer VK_F19 = 130 Integer VK_F20 = 131 Integer VK_F21 = 132 Integer VK_F22 = 133 Integer VK_F23 = 134 Integer VK_F24 = 135 Integer VK_NUMLOCK = 144 Integer VK_SCROLL = 145 |
Good Luck!