\ File: keystate.spf \ Date: 09.10.2004 \ Author: Nicholas Nemtsev, Valery Kondakoff \ Description: Finding out whether the specified key on your keyboard is \ currently pressed down or not (KEY-PRESSED?). Using \ KEY-PRESSED? word you can find out if the specified mouse \ button is held down as well. Determines the toggle status \ of 'Caps Lock', 'Scroll Lock' and 'Num Lock' buttons \ (KEY-TOGGLED?). \ New words: KEY-PRESSED? ( n -- ? ) \ KEY-TOGGLED? ( n -- ? ) \ Usage: KEY-PRESSED? IF ... THEN \ KEY-TOGGLED? IF ... THEN 0 [IF] \ this is a comment string Examples: #( test_keystate NoActive \ finding out if 'Caps Lock' is set to ON Action: VK_CAPITAL KEY-TOGGLED? IF MSG: "Caps Lock is ON" ELSE MSG: "Caps Lock is OFF" THEN )# #( test_ctrl_press \ 'beeps' every time user press the CTRL key SingleInstance Action: BEGIN VK_CONTROL KEY-PRESSED? IF BEEP: 500 500 THEN PAUSE: 100 AGAIN )# #( test_min2tray_mouseRB \ put the current window into system tray by \ right-clicking on the 'Minimize' button SingleInstance VARIABLE allowMB \ this flag allows to minimize the current window Action: BEGIN VK_RBUTTON KEY-PRESSED? \ right mouse button IF allowMB @ \ first press? IF MOUSE-POS 16 LSHIFT OR \ converting x,y to lParam \ checking the cursor position: 0 132 GetForegroundWindow SendMessageA 8 = \ if the cursor is on the Minimie button: IF WIN-TO-TRAY: "%GetForegroundWindow%" THEN allowMB OFF \ set flag to OFF THEN ELSE \ the mouse button was released, set the flag to ON: allowMB ON THEN PAUSE: 100 AGAIN )# [THEN] \ this is a comment string WINAPI: GetKeyState USER32.DLL : KEY-PRESSED? ( n -- ? ) GetKeyState 128 AND? ; : KEY-TOGGLED? ( n -- ? ) GetKeyState 1 AND? ; \ If the desired virtual key is a letter or digit (A-Z, a-z, or 0-9), you \ must use the ASCII value of that character. For other keys, you should \ use virtual-key code constants (like VK_CAPITAL, VK_NUMLOCK etc) or \ their numerical values. This is a list of available virtual-key code \ constants and their numerical values: 20 CONSTANT VK_CAPITAL \ (Caps Lock) 144 CONSTANT VK_NUMLOCK \ (Num Lock) 145 CONSTANT VK_SCROLL \ (Scroll Lock) 1 CONSTANT VK_LBUTTON \ (Left Mouse Button) 4 CONSTANT VK_MBUTTON \ (Middle Mouse Button) 2 CONSTANT VK_RBUTTON \ (Right Mouse Button) 107 CONSTANT VK_ADD 93 CONSTANT VK_APPS 246 CONSTANT VK_ATTN 8 CONSTANT VK_BACK 3 CONSTANT VK_CANCEL 12 CONSTANT VK_CLEAR 17 CONSTANT VK_CONTROL 247 CONSTANT VK_CRSEL 110 CONSTANT VK_DECIMAL 46 CONSTANT VK_DELETE 111 CONSTANT VK_DIVIDE 40 CONSTANT VK_DOWN 35 CONSTANT VK_END 249 CONSTANT VK_EREOF 27 CONSTANT VK_ESCAPE 43 CONSTANT VK_EXECUTE 248 CONSTANT VK_EXSEL 112 CONSTANT VK_F1 121 CONSTANT VK_F10 122 CONSTANT VK_F11 123 CONSTANT VK_F12 124 CONSTANT VK_F13 125 CONSTANT VK_F14 126 CONSTANT VK_F15 127 CONSTANT VK_F16 128 CONSTANT VK_F17 129 CONSTANT VK_F18 130 CONSTANT VK_F19 113 CONSTANT VK_F2 131 CONSTANT VK_F20 132 CONSTANT VK_F21 133 CONSTANT VK_F22 134 CONSTANT VK_F23 135 CONSTANT VK_F24 114 CONSTANT VK_F3 115 CONSTANT VK_F4 116 CONSTANT VK_F5 117 CONSTANT VK_F6 118 CONSTANT VK_F7 119 CONSTANT VK_F8 120 CONSTANT VK_F9 47 CONSTANT VK_HELP 36 CONSTANT VK_HOME 45 CONSTANT VK_INSERT 162 CONSTANT VK_LCONTROL 37 CONSTANT VK_LEFT 164 CONSTANT VK_LMENU 160 CONSTANT VK_LSHIFT 91 CONSTANT VK_LWIN 18 CONSTANT VK_MENU 106 CONSTANT VK_MULTIPLY 34 CONSTANT VK_NEXT 252 CONSTANT VK_NONAME 96 CONSTANT VK_NUMPAD0 97 CONSTANT VK_NUMPAD1 98 CONSTANT VK_NUMPAD2 99 CONSTANT VK_NUMPAD3 100 CONSTANT VK_NUMPAD4 101 CONSTANT VK_NUMPAD5 102 CONSTANT VK_NUMPAD6 103 CONSTANT VK_NUMPAD7 104 CONSTANT VK_NUMPAD8 105 CONSTANT VK_NUMPAD9 254 CONSTANT VK_OEM_CLEAR 253 CONSTANT VK_PA1 19 CONSTANT VK_PAUSE 250 CONSTANT VK_PLAY 42 CONSTANT VK_PRINT 33 CONSTANT VK_PRIOR 229 CONSTANT VK_PROCESSKEY 163 CONSTANT VK_RCONTROL 13 CONSTANT VK_RETURN 39 CONSTANT VK_RIGHT 165 CONSTANT VK_RMENU 161 CONSTANT VK_RSHIFT 92 CONSTANT VK_RWIN 41 CONSTANT VK_SELECT 108 CONSTANT VK_SEPARATOR 16 CONSTANT VK_SHIFT 44 CONSTANT VK_SNAPSHOT 32 CONSTANT VK_SPACE 109 CONSTANT VK_SUBTRACT 9 CONSTANT VK_TAB 38 CONSTANT VK_UP 251 CONSTANT VK_ZOOM