Jump to content

Getting The Last Key Pressed.


Recommended Posts

I need to get the last key pressed in a form that is compatible with Send(). For instance it must differentiate between 1 and {numpad1}.

Even if I cannot differentiate it would be nice if there was a way to wait for any key to be pressed. I know of _IsPressed but I am hoping there is an easier and less strenuous way then waiting for any in a huge list of keys to be pressed.

Edited by Christopher Blue
Link to comment
Share on other sites

Here's some code for you:

A UDF that waits for a keypress then returns it.

;;;A UDF
#include <Misc.au3>
Func _WaitForKeypress()
   While 1
      For $c = 8 To 165
         If _IsPressed($c) Then 
            Return($c)
         EndIf
      Next
      Sleep(20)
   WEnd
EndFunc

A UDF that waits for keypresses and mouseclicks then returns it:

Func _WaitForKeypressOrClick()
   While 1
      For $c = 1 To 165
         If _IsPressed($c) Then 
            Return($c)
         EndIf
      Next
      Sleep(20)
   WEnd
EndFunc

Array of keycodes:

$InputManager_KeyCodes[0x01] = 'Left mouse button'
$InputManager_KeyCodes[0x02] = 'Right mouse button'
$InputManager_KeyCodes[0x04] = 'Middle mouse button'
$InputManager_KeyCodes[0x05] = 'X1 mouse button'
$InputManager_KeyCodes[0x06] = 'X2 mouse button'
$InputManager_KeyCodes[0x08] = 'BACKSPACE '
$InputManager_KeyCodes[0x09] = 'TAB'
$InputManager_KeyCodes[0x0C] = 'CLEAR'
$InputManager_KeyCodes[0x0D] = 'ENTER'
$InputManager_KeyCodes[0x10] = 'SHIFT '
$InputManager_KeyCodes[0x11] = 'CTRL '
$InputManager_KeyCodes[0x12] = 'ALT '
$InputManager_KeyCodes[0x13] = 'PAUSE '
$InputManager_KeyCodes[0x14] = 'CAPS LOCK '
$InputManager_KeyCodes[0x1B] = 'ESC'
$InputManager_KeyCodes[0x20] = 'SPACE'
$InputManager_KeyCodes[0x21] = 'PAGE UP'
$InputManager_KeyCodes[0x22] = 'PAGE DOWN'
$InputManager_KeyCodes[0x23] = 'END'
$InputManager_KeyCodes[0x24] = 'HOME'
$InputManager_KeyCodes[0x25] = 'LEFT ARROW'
$InputManager_KeyCodes[0x26] = 'UP ARROW'
$InputManager_KeyCodes[0x27] = 'RIGHT ARROW'
$InputManager_KeyCodes[0x28] = 'DOWN ARROW'
$InputManager_KeyCodes[0x29] = 'SELECT '
$InputManager_KeyCodes[0x2A] = 'PRINT'
$InputManager_KeyCodes[0x2B] = 'EXECUTE'
$InputManager_KeyCodes[0x2C] = 'PRINT SCREEN'
$InputManager_KeyCodes[0x2D] = 'INS '
$InputManager_KeyCodes[0x2E] = 'DEL '
$InputManager_KeyCodes[0x30] = '0'
$InputManager_KeyCodes[0x31] = '1'
$InputManager_KeyCodes[0x32] = '2'
$InputManager_KeyCodes[0x33] = '3'
$InputManager_KeyCodes[0x34] = '4'
$InputManager_KeyCodes[0x35] = '5'
$InputManager_KeyCodes[0x36] = '6'
$InputManager_KeyCodes[0x37] = '7'
$InputManager_KeyCodes[0x38] = '8'
$InputManager_KeyCodes[0x39] = '9'
$InputManager_KeyCodes[0x41] = 'A'
$InputManager_KeyCodes[0x42] = 'B'
$InputManager_KeyCodes[0x43] = 'C'
$InputManager_KeyCodes[0x44] = 'D'
$InputManager_KeyCodes[0x45] = 'E'
$InputManager_KeyCodes[0x46] = 'F'
$InputManager_KeyCodes[0x47] = 'G'
$InputManager_KeyCodes[0x48] = 'H'
$InputManager_KeyCodes[0x49] = 'I'
$InputManager_KeyCodes[0x4A] = 'J'
$InputManager_KeyCodes[0x4B] = 'K'
$InputManager_KeyCodes[0x4C] = 'L'
$InputManager_KeyCodes[0x4D] = 'M'
$InputManager_KeyCodes[0x4E] = 'N'
$InputManager_KeyCodes[0x4F] = 'O'
$InputManager_KeyCodes[0x50] = 'P'
$InputManager_KeyCodes[0x51] = 'Q'
$InputManager_KeyCodes[0x52] = 'R'
$InputManager_KeyCodes[0x53] = 'S'
$InputManager_KeyCodes[0x54] = 'T'
$InputManager_KeyCodes[0x55] = 'U'
$InputManager_KeyCodes[0x56] = 'V'
$InputManager_KeyCodes[0x57] = 'W'
$InputManager_KeyCodes[0x58] = 'X'
$InputManager_KeyCodes[0x59] = 'Y'
$InputManager_KeyCodes[0x5A] = 'Z'
$InputManager_KeyCodes[0x5B] = 'Left Windows'
$InputManager_KeyCodes[0x5C] = 'Right Windows'
$InputManager_KeyCodes[0x60] = 'Numeric pad 0'
$InputManager_KeyCodes[0x61] = 'Numeric pad 1'
$InputManager_KeyCodes[0x62] = 'Numeric pad 2'
$InputManager_KeyCodes[0x63] = 'Numeric pad 3'
$InputManager_KeyCodes[0x64] = 'Numeric pad 4'
$InputManager_KeyCodes[0x65] = 'Numeric pad 5'
$InputManager_KeyCodes[0x66] = 'Numeric pad 6'
$InputManager_KeyCodes[0x67] = 'Numeric pad 7'
$InputManager_KeyCodes[0x68] = 'Numeric pad 8'
$InputManager_KeyCodes[0x69] = 'Numeric pad 9'
$InputManager_KeyCodes[0x6A] = 'Multiply'
$InputManager_KeyCodes[0x6B] = 'Add'
$InputManager_KeyCodes[0x6C] = 'Separator'
$InputManager_KeyCodes[0x6D] = 'Subtract'
$InputManager_KeyCodes[0x6E] = 'Decimal'
$InputManager_KeyCodes[0x6F] = 'Divide'
$InputManager_KeyCodes[0x70] = 'F1'
$InputManager_KeyCodes[0x71] = 'F2'
$InputManager_KeyCodes[0x72] = 'F3'
$InputManager_KeyCodes[0x73] = 'F4'
$InputManager_KeyCodes[0x74] = 'F5'
$InputManager_KeyCodes[0x75] = 'F6'
$InputManager_KeyCodes[0x76] = 'F7'
$InputManager_KeyCodes[0x77] = 'F8'
$InputManager_KeyCodes[0x78] = 'F9'
$InputManager_KeyCodes[0x79] = 'F10'
$InputManager_KeyCodes[0x7A] = 'F11'
$InputManager_KeyCodes[0x7B] = 'F12'
$InputManager_KeyCodes[0x7C] = 'F13'
$InputManager_KeyCodes[0x7D] = 'F14'
$InputManager_KeyCodes[0x7E] = 'F15'
$InputManager_KeyCodes[0x7F] = 'F16'
$InputManager_KeyCodes[0x80] = 'F17'
$InputManager_KeyCodes[0x81] = 'F18'
$InputManager_KeyCodes[0x82] = 'F19'
$InputManager_KeyCodes[0x83] = 'F20'
$InputManager_KeyCodes[0x84] = 'F21'
$InputManager_KeyCodes[0x85] = 'F22'
$InputManager_KeyCodes[0x86] = 'F23'
$InputManager_KeyCodes[0x87] = 'F24'
$InputManager_KeyCodes[0x90] = 'NUM LOCK'
$InputManager_KeyCodes[0x91] = 'SCROLL LOCK'
$InputManager_KeyCodes[0xA0] = 'Left SHIFT'
$InputManager_KeyCodes[0xA1] = 'Right SHIFT'
$InputManager_KeyCodes[0xA2] = 'Left CONTROL'
$InputManager_KeyCodes[0xA3] = 'Right CONTROL'
$InputManager_KeyCodes[0xA4] = 'Left MENU'
$InputManager_KeyCodes[0xA5] = 'Right MENU'

#)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...