Core Function RealGetKeyState
(→Example) |
(→Remarks) |
||
Line 40: | Line 40: | ||
<pre> | <pre> | ||
+ | {ONCE} Must be used by itself this is a special code | ||
+ | that tells the RealGetKeyState() to only trigger | ||
+ | if the keys are press ONCE (it will only trigger | ||
+ | again if the user releases the hotkeys then presses | ||
+ | the hotkeys again) | ||
{SPACE} SPACE | {SPACE} SPACE | ||
{ENTER} ENTER key on the main keyboard | {ENTER} ENTER key on the main keyboard |
Revision as of 12:33, 29 January 2013
RealGetKeyState( <vk_keycode/expression> )
Contents |
Description
Checks if a key or series of keys is pressed down.
Parameters
vk_keycode/expression
If this param is numeric then a virtual key code (See Macros) is needed.
If this param is a string then it will check all the chars in the string + any specials see remarks.
Note - You can add an unlimited number of params
Return Value
Success: Returns 1.
Failure: Returns 0.
Remarks
It should be noted this function only check if the key/keys are down when the function is called only it is not the same as HotKeySet() since this only checks when its called and not again.
However you could create a timer or loop to check for keys being pressed creating a kind of Hotkey system the best setting for HotKeys is probably a timer with 100 millisecond interval.
Special symbols to use when the param is a string
! Alt Key ^ Control Key + Shift Key # Windows Key
Special {} to use when the param is a string
{ONCE} Must be used by itself this is a special code that tells the RealGetKeyState() to only trigger if the keys are press ONCE (it will only trigger again if the user releases the hotkeys then presses the hotkeys again) {SPACE} SPACE {ENTER} ENTER key on the main keyboard {ALT} ALT {BACKSPACE} or {BS} BACKSPACE {DELETE} or {DEL} DELETE {UP} Cursor up {DOWN} Cursor down {LEFT} Cursor left {RIGHT} Cursor right {HOME} HOME {END} END {ESCAPE} or {ESC} ESCAPE {INSERT} or {INS} INS {PGUP} PageUp {PGDN} PageDown {F1} - {F12} Function keys {TAB} TAB {PRINTSCREEN} Print Screen key {LWIN} Left Windows key {RWIN} Right Windows key {NUMLOCK} NUMLOCK {CAPSLOCK} CAPSLOCK {SCROLLLOCK} SCROLLLOCK {CTRLBREAK} Ctrl+Break {PAUSE} PAUSE {NUMPAD0} - {NUMPAD9} Numpad digits {NUMPADMULT} Numpad Multiply {NUMPADADD} Numpad Add {NUMPADSUB} Numpad Subtract {NUMPADDIV} Numpad Divide {NUMPADDOT} Numpad period {NUMPADENTER} Enter key on the numpad {APPSKEY} Windows App key {LALT} Left ALT key {RALT} Right ALT key {LCTRL} Left CTRL key {RCTRL} Right CTRL key {LSHIFT} Left Shift key {RSHIFT} Right Shift key {SLEEP} Computer SLEEP key
Example
Example of using the first param as numeric to scan for a single VK key
println("Try pressing B or C or Shift+A or Shift+Control+D or Shift+Control+Alt+E"); while(true) { if( RealGetKeyState(@KeyB) ) { println("B is pressed"); } if( RealGetKeyState(@KeyC) ) { println("C is pressed"); } if( RealGetKeyState(@KeyShiftKey) && RealGetKeyState(@KeyA) ) { println("Shift+A is pressed"); } if( RealGetKeyState(@KeyShiftKey) && RealGetKeyState(@KeyControlKey) && RealGetKeyState(@KeyD) ) { println("Shift+Control+D is pressed"); } if( RealGetKeyState(@KeyShiftKey) && RealGetKeyState(@KeyControlKey) && RealGetKeyState(@KeyMenu) && RealGetKeyState(@KeyE) ) { println("Shift+Control+Alt+E is pressed"); } sleep(100); }
Example of using the first param as a string to scan for sequence of keys this is same as the above example but using the param as a string instead
println("Try pressing B or C or Shift+A or Shift+Control+D or Shift+Control+Alt+E"); while(true) { if( RealGetKeyState("b") ) { println("B is pressed"); } if( RealGetKeyState("c") ) { println("C is pressed"); } if(RealGetKeyState("+a")) { println("Shift+A is pressed"); } if(RealGetKeyState("+^d")) { println("Shift+Control+D is pressed"); } if(RealGetKeyState("+^!e")) { println("Shift+Control+Alt+E is pressed"); } sleep(100); }
Another example of using the first param as a string to scan for sequence of keys
while(true) { // Only triggers when SHIFT + NUMLOCK + A are all pressed down if( RealGetKeyState( "+{NUMLOCK}a" ) ) { println("Key sequence was pressed"); } sleep(100); }
Example of using more than one param
while(true) { if( RealGetKeyState("b", @KeyC) ) { println("B+C is pressed"); } sleep(100); }