Keyboard Control

From SolarStrike wiki
Revision as of 22:36, 13 July 2008 by Elverion (talk | contribs) (New page: == keyboardPress == '''keyboardPress(key)''' Simulates the pressing of the specified key. See Virtual Keys for more information. If you are running input in attached mode (through us...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

keyboardPress

keyboardPress(key)

Simulates the pressing of the specified key. See Virtual Keys for more information.

If you are running input in attached mode (through use of attach()) it will only send input to the target window, and will not interfere if you decide to switch windows.

If the target program does not appear to be picking up input through the use of this function, you might try calling keyboardSetDelay() somewhere in your script to increase the delay.


Example

keyboardPress( key.VK_ENTER ); -- The ENTER key will be pressed


keyboardHold

keyboardHold(key)

Holds the specified key until it is pressed or released (either physically, or virtually). See Virtual Keys for more information.

If you are running input in attached mode (through use of attach()) it will only send input to the target window, and will not interfere if you decide to switch windows.

If the target program does not appear to be picking up input through the use of this function, you might try calling keyboardSetDelay() somewhere in your script to increase the delay.


Example

keyboardHold( key.VK_A ); -- The A key will be held down
yrest(50);
keyboardRelease( key.VK_A ); -- The A key is now released


keyboardRelease

keyboardRelease(key)

Releases the specified key. See Virtual Keys for more information.

If you are running input in attached mode (through use of attach()) it will only send input to the target window, and will not interfere if you decide to switch windows.

If the target program does not appear to be picking up input through the use of this function, you might try calling keyboardSetDelay() somewhere in your script to increase the delay.


Example

keyboardRelease( key.VK_A ); -- A is no longer being held


keyPressed

int keyPressed(key)

Checks if a key is being held down or pressed. Returns a boolean: true if held/pressed, otherwise returns false. See Virtual Keys for more information.

The check for this is done globally, meaning that you do not need to have the calling MicroMacro window, or it's attached window, focused for a keypress to register. If you only want to gather input from MicroMacro or it's attached window, use keyPressedLocal() instead.


Example

if( keyPressed( key.VK_A ) ) then
  -- A is pressed. Do something!
end

keyPressedLocal

int keyPressedLocal(key)

Checks if a key is being held down or pressed. Returns a boolean: true if held/pressed, otherwise returns false. See Virtual Keys for more information.

The check for this is done locally, meaning that you must have the calling MicroMacro window, or it's attached window, focused for a keypress to register. If you want to gather input globally, use keyPressed() instead.


Example

if( keyPressedLocal( key.VK_A ) ) then
  -- A is pressed. Do something!
end

keyboardType

keyboardType(message)

Types the message specified, as if typed by the user.


Example

keyboardType("This is an example! ;)");  -- This will output the following text: This is an example! ;)

keyboardSetDelay

keyboardSetDelay(time)

Sets the automatic delay between key presses and releases for functions like keyboardType() or keyboardPress(). 'time' is specified in miliseconds. If the target program does not appear to be picking up input well using the current delay, use this function to increase it and give the target program more time to detect the press/release. Note that it will then take longer to process the key press if you increase the delay.

The default keyboard delay is 50ms.


Example

keyboardSetDelay(100);
keyboardType("This is an example! ;)");  -- This will output the string with 100ms delay between each character

getKeyName

string getKeyName(key)

Returns the symbolic name for the key specified. That is, passing key.VK_SPACE to getKeyName() will result in the function returning "SPACE". This function is affected by your computer's language settings.


Example

printf("Keyname: %s\n", getKeyName(key.VK_SPACE));