Core Function RealGetKeyState

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
Line 1: Line 1:
 
<pre>
 
<pre>
RealGetKeyState( <vk_keycode> )
+
RealGetKeyState( <vk_keycode/expression> )  
 
</pre>
 
</pre>
  
 
=== Description ===
 
=== Description ===
  
Checks if a key is pressed down.
+
Checks if a key or series of keys is pressed down.
  
 
=== Parameters ===
 
=== Parameters ===
  
==== vk_keycode ====
+
==== vk_keycode/expression ====
  
A virtual key code (See [[Macros|Macros]]).
+
If this param is numeric then a virtual key code (See [[Macros|Macros]]) is needed.
 +
 
 +
If this param is a string then it will check all the chars in the string + any specials see remarks.
  
 
=== Return Value ===
 
=== Return Value ===
Line 19: Line 21:
 
=== Remarks ===
 
=== Remarks ===
  
None.
+
Special symbols to use when the param is a string
 +
<pre>
 +
! Alt Key
 +
^ Control Key
 +
+ Shift Key
 +
# Windows Key
 +
</pre>
 +
 
 +
Special {} to use when the param is a string
 +
 
 +
<pre>
 +
{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
 +
</pre>
  
 
=== Example ===
 
=== Example ===
 +
 +
Example of using the first param as numeric to scan for a single VK key
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
Line 66: Line 121:
  
  
 +
sleep(100);
 +
}
 +
</syntaxhighlight>
 +
 +
Example of using the first param as a string to scan for sequence of keys
 +
 +
<syntaxhighlight lang="sputnik">
 +
while(true)
 +
{
 +
// Only triggers when SHIFT + NUMLOCK + A is pressed
 +
if( RealGetKeyState( "+{NUMLOCK}a" ) )
 +
{
 +
println("Key sequence was pressed");
 +
}
 
sleep(100);
 
sleep(100);
 
}
 
}

Revision as of 06:20, 30 April 2012

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.

Return Value

None

Remarks

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

{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

while(true)
{
	// Only triggers when SHIFT + NUMLOCK + A is pressed
	if( RealGetKeyState( "+{NUMLOCK}a" ) )
	{
		println("Key sequence was pressed");
	}
	sleep(100);
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox