Make your own free website on Tripod.com

Set & Get Caps/Num/Scroll keys (PB6, Apr 13, 1999)

Back Up Next

Author: Eric Aling (14 jul 1999)
Accessed:
Download: Download kbs.zip (8 kb) (KBS.zip, 8kb)

In some cases, you want for instance programmatically set the CAPS lock key. Windows provide us with two functions:

function boolean SetKeyboardState( char lpKeyState[256] ) library 'user32.dll'
function boolean GetKeyboardState( REF char lpKeyState[256] ) library 'user32.dll'

The 'set' function is used to turn the specific key on the keyboard on or off. The 'get' function returns the current state of the keyboard. All keys on the keyboard have a specific number and are identified by a virtual key code such as VK_CAPITAL, which is nothing more than a index (=20) in the KeyState[] array. So, if you want to turn on the CAPS lock key, set index 20 in the array to '1' and call the 'set' function. Simple, right? Same thing otherway around. To check if the CAPS lock key is on, call the 'get' function and check index 20. If it is '0', the CAPS lock key is off, else it is on.

Note: the CAPS lock key state is bound to the application. That means: if I turn the CAPS lock key on in my application, it stays off for other applications.

Check out the simple KBS example.

Hereby also a list with virtual key codes from the Win32 API helpfile:

CONSTANT integer VK_LBUTTON = 1
CONSTANT integer VK_RBUTTON = 2
CONSTANT integer VK_CANCEL = 3
CONSTANT integer VK_MBUTTON = 4 /* NOT contiguous with L & RBUTTON */

CONSTANT integer VK_BACK = 8
CONSTANT integer VK_TAB = 9
CONSTANT integer VK_SHIFT = 10

CONSTANT integer VK_CLEAR = 12
CONSTANT integer VK_RETURN = 13

CONSTANT integer VK_CONTROL = 17
CONSTANT integer VK_MENU = 18
CONSTANT integer VK_PAUSE = 19
CONSTANT integer VK_CAPITAL = 20

CONSTANT integer VK_ESCAPE = 27

CONSTANT integer VK_SPACE = 32
CONSTANT integer VK_PRIOR = 33
CONSTANT integer VK_NEXT = 34
CONSTANT integer VK_END = 35
CONSTANT integer VK_HOME = 36
CONSTANT integer VK_LEFT = 37
CONSTANT integer VK_UP = 38
CONSTANT integer VK_RIGHT = 39
CONSTANT integer VK_DOWN = 40
CONSTANT integer VK_SELECT = 41
CONSTANT integer VK_PRINT = 42
CONSTANT integer VK_EXECUTE = 43
CONSTANT integer VK_SNAPSHOT = 44
CONSTANT integer VK_INSERT = 45
CONSTANT integer VK_DELETE = 46
CONSTANT 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) */

CONSTANT integer VK_LWIN = 91
CONSTANT integer VK_RWIN = 92
CONSTANT integer VK_APPS = 93

CONSTANT integer VK_NUMPAD0 = 96
CONSTANT integer VK_NUMPAD1 = 97
CONSTANT integer VK_NUMPAD2 = 98
CONSTANT integer VK_NUMPAD3 = 99
CONSTANT integer VK_NUMPAD4 = 100
CONSTANT integer VK_NUMPAD5 = 101
CONSTANT integer VK_NUMPAD6 = 102
CONSTANT integer VK_NUMPAD7 = 103
CONSTANT integer VK_NUMPAD8 = 104
CONSTANT integer VK_NUMPAD9 = 105
CONSTANT integer VK_MULTIPLY = 106
CONSTANT integer VK_ADD = 107
CONSTANT integer VK_SEPARATOR = 108
CONSTANT integer VK_SUBTRACT = 109
CONSTANT integer VK_DECIMAL = 110
CONSTANT integer VK_DIVIDE = 111
CONSTANT integer VK_F1 = 112
CONSTANT integer VK_F2 = 113
CONSTANT integer VK_F3 = 114
CONSTANT integer VK_F4 = 115
CONSTANT integer VK_F5 = 116
CONSTANT integer VK_F6 = 117
CONSTANT integer VK_F7 = 118
CONSTANT integer VK_F8 = 119
CONSTANT integer VK_F9 = 120
CONSTANT integer VK_F10 = 121
CONSTANT integer VK_F11 = 122
CONSTANT integer VK_F12 = 123
CONSTANT integer VK_F13 = 124
CONSTANT integer VK_F14 = 125
CONSTANT integer VK_F15 = 126
CONSTANT integer VK_F16 = 127
CONSTANT integer VK_F17 = 128
CONSTANT integer VK_F18 = 129
CONSTANT integer VK_F19 = 130
CONSTANT integer VK_F20 = 131
CONSTANT integer VK_F21 = 132
CONSTANT integer VK_F22 = 133
CONSTANT integer VK_F23 = 134
CONSTANT integer VK_F24 = 135

CONSTANT integer VK_NUMLOCK = 144
CONSTANT integer VK_SCROLL = 145

 

 

Back Up Next