Replacement for Windows keyboard input

BlitzMax Forums/BlitzMax Module Tweaks/Replacement for Windows keyboard input

JoshK(Posted 2007) [#1]
If you are having problems with keyboard input on Windows, you can always use this:
Function KeyDown:Int(key:Int)
	Select GetAsyncKeyState(key)
		Case 32767,32768,-32767,-32768
			Return True
		Default
			Return False
	EndSelect
EndFunction

Function KeyHit:Int(key:Int)
	Select GetAsyncKeyState(key)
		Case 32767,-32767
			Return True
		Default
			Return False
	EndSelect
EndFunction

Const KEY_BACKSPACE=$08
Const KEY_TAB=$09
Const KEY_CLEAR=$10
Const KEY_ENTER=$0D
Const KEY_SHIFT=$10
Const KEY_CTRL=$11
Const KEY_ALT=$12
Const KEY_PAUSE=$13
Const KEY_CAPSLOCK=$14
Const KEY_ESCAPE=$1B
Const KEY_SPACE=$20
Const KEY_PAGEUP=$21
Const KEY_PAGEDOWN=$22
Const KEY_END=$23
Const KEY_HOME=$24
Const KEY_LEFT=$25
Const KEY_UP=$26
Const KEY_RIGHT=$27
Const KEY_DOWN=$28
Const KEY_SELECT=$29
Const KEY_PRINT=$2A
Const KEY_EXECUTE=$2B
Const KEY_PRTSCRN=$2C
Const KEY_INSERT=$2D
Const KEY_DELETE=$2E
Const KEY_HELP=$2F
Const KEY_0=$30
Const KEY_1=$31
Const KEY_2=$32
Const KEY_3=$33
Const KEY_4=$34
Const KEY_5=$35
Const KEY_6=$36
Const KEY_7=$37
Const KEY_8=$38
Const KEY_9=$39
Const KEY_A=$41
Const KEY_B=$42
Const KEY_C=$43
Const KEY_D=$44
Const KEY_E=$45
Const KEY_F=$46
Const KEY_G=$47
Const KEY_H=$48
Const KEY_I=$49
Const KEY_J=$4A
Const KEY_K=$4B
Const KEY_L=$4C
Const KEY_M=$4D
Const KEY_N=$4E
Const KEY_O=$4F
Const KEY_P=$50
Const KEY_Q=$51
Const KEY_R=$52
Const KEY_S=$53
Const KEY_T=$54
Const KEY_U=$55
Const KEY_V=$56
Const KEY_W=$57
Const KEY_X=$58
Const KEY_Y=$59
Const KEY_Z=$5A

Rem
    VK_LWIN (5B)
        Left Windows key (Microsoft Natural keyboard) 

    VK_RWIN (5C)
        Right Windows key (Natural keyboard)

    VK_APPS (5D)
        Applications key (Natural keyboard)

    - (5E)
        Reserved

    VK_SLEEP (5F)
        Computer Sleep key

    VK_NUMPAD0 (60)
        Numeric keypad 0 key

    VK_NUMPAD1 (61)
        Numeric keypad 1 key

    VK_NUMPAD2 (62)
        Numeric keypad 2 key

    VK_NUMPAD3 (63)
        Numeric keypad 3 key

    VK_NUMPAD4 (64)
        Numeric keypad 4 key

    VK_NUMPAD5 (65)
        Numeric keypad 5 key

    VK_NUMPAD6 (66)
        Numeric keypad 6 key

    VK_NUMPAD7 (67)
        Numeric keypad 7 key

    VK_NUMPAD8 (68)
        Numeric keypad 8 key

    VK_NUMPAD9 (69)
        Numeric keypad 9 key

    VK_MULTIPLY (6A)
        Multiply key

    VK_ADD (6B)
        Add key

    VK_SEPARATOR (6C)
        Separator key

    VK_SUBTRACT (6D)
        Subtract key

    VK_DECIMAL (6E)
        Decimal key

    VK_DIVIDE (6F)
        Divide key

    VK_F1 (70)
        F1 key

    VK_F2 (71)
        F2 key

    VK_F3 (72)
        F3 key

    VK_F4 (73)
        F4 key

    VK_F5 (74)
        F5 key

    VK_F6 (75)
        F6 key

    VK_F7 (76)
        F7 key

    VK_F8 (77)
        F8 key

    VK_F9 (78)
        F9 key

    VK_F10 (79)
        F10 key

    VK_F11 (7A)
        F11 key

    VK_F12 (7B)
        F12 key

    VK_F13 (7C)
        F13 key

    VK_F14 (7D)
        F14 key

    VK_F15 (7E)
        F15 key

    VK_F16 (7F)
        F16 key

    VK_F17 (80H)
        F17 key

    VK_F18 (81H)
        F18 key

    VK_F19 (82H)
        F19 key

    VK_F20 (83H)
        F20 key

    VK_F21 (84H)
        F21 key

    VK_F22 (85H)
        F22 key

    VK_F23 (86H)
        F23 key

    VK_F24 (87H)
        F24 key

    - (88-8F)
        Unassigned

    VK_NUMLOCK (90)
        NUM LOCK key

    VK_SCROLL (91)
        SCROLL LOCK key

     (92-96)
        OEM specific

    - (97-9F)
        Unassigned

    VK_LSHIFT (A0)
        Left SHIFT key

    VK_RSHIFT (A1)
        Right SHIFT key

    VK_LCONTROL (A2)
        Left CONTROL key

    VK_RCONTROL (A3)
        Right CONTROL key

    VK_LMENU (A4)
        Left MENU key

    VK_RMENU (A5)
        Right MENU key

    VK_BROWSER_BACK (A6)
        Windows 2000/XP: Browser Back key

    VK_BROWSER_FORWARD (A7)
        Windows 2000/XP: Browser Forward key

    VK_BROWSER_REFRESH (A8)
        Windows 2000/XP: Browser Refresh key

    VK_BROWSER_STOP (A9)
        Windows 2000/XP: Browser Stop key

    VK_BROWSER_SEARCH (AA)
        Windows 2000/XP: Browser Search key 

    VK_BROWSER_FAVORITES (AB)
        Windows 2000/XP: Browser Favorites key

    VK_BROWSER_HOME (AC)
        Windows 2000/XP: Browser Start And Home key

    VK_VOLUME_MUTE (AD)
        Windows 2000/XP: Volume Mute key

    VK_VOLUME_DOWN (AE)
        Windows 2000/XP: Volume Down key

    VK_VOLUME_UP (AF)
        Windows 2000/XP: Volume Up key

    VK_MEDIA_NEXT_TRACK (B0)
        Windows 2000/XP: Next Track key

    VK_MEDIA_PREV_TRACK (B1)
        Windows 2000/XP: Previous Track key

    VK_MEDIA_STOP (B2)
        Windows 2000/XP: Stop Media key

    VK_MEDIA_PLAY_PAUSE (B3)
        Windows 2000/XP: Play/Pause Media key

    VK_LAUNCH_MAIL (B4)
        Windows 2000/XP: Start Mail key

    VK_LAUNCH_MEDIA_SELECT (B5)
        Windows 2000/XP: Select Media key

    VK_LAUNCH_APP1 (B6)
        Windows 2000/XP: Start Application 1 key

    VK_LAUNCH_APP2 (B7)
        Windows 2000/XP: Start Application 2 key

    - (B8-B9)
        Reserved

    VK_OEM_1 (BA)
        Used For miscellaneous characters; it can vary by keyboard.

        Windows 2000/XP: For the US standard keyboard, the ';:' key 

    VK_OEM_PLUS (BB)
        Windows 2000/XP: For any country/region, the '+' key

    VK_OEM_COMMA (BC)
        Windows 2000/XP: For any country/region, the ',' key

    VK_OEM_MINUS (BD)
        Windows 2000/XP: For any country/region, the '-' key

    VK_OEM_PERIOD (BE)
        Windows 2000/XP: For any country/region, the '.' key

    VK_OEM_2 (BF)
        Used For miscellaneous characters; it can vary by keyboard.

        Windows 2000/XP: For the US standard keyboard, the '/?' key 

    VK_OEM_3 (C0)
        Used For miscellaneous characters; it can vary by keyboard.

        Windows 2000/XP: For the US standard keyboard, the '`~' key 

    - (C1-D7)
        Reserved

    - (D8-DA)
        Unassigned

    VK_OEM_4 (DB)
        Used For miscellaneous characters; it can vary by keyboard.

        Windows 2000/XP: For the US standard keyboard, the '[{' key

    VK_OEM_5 (DC)
        Used For miscellaneous characters; it can vary by keyboard.

        Windows 2000/XP: For the US standard keyboard, the '\|' key

    VK_OEM_6 (DD)
        Used For miscellaneous characters; it can vary by keyboard.

        Windows 2000/XP: For the US standard keyboard, the ']}' key

    VK_OEM_7 (DE)
        Used For miscellaneous characters; it can vary by keyboard.

        Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key

    VK_OEM_8 (DF)
        Used For miscellaneous characters; it can vary by keyboard.

    - (E0)
        Reserved

     (E1)
        OEM specific

    VK_OEM_102 (E2)
        Windows 2000/XP: Either the angle bracket key Or the backslash key on the RT 102-key keyboard

     (E3-E4)
        OEM specific

    VK_PROCESSKEY (E5)
        Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key

     (E6)
        OEM specific

    VK_PACKET (E7)
        Windows 2000/XP: Used To pass Unicode characters as If they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used For non-keyboard Input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, And WM_KEYUP

    - (E8)
        Unassigned

     (E9-F5)
        OEM specific

    VK_ATTN (F6)
        Attn key

    VK_CRSEL (F7)
        CrSel key

    VK_EXSEL (F8)
        ExSel key

    VK_EREOF (F9)
        Erase Eof key

    VK_PLAY (FA)
        Play key

    VK_ZOOM (FB)
        Zoom key

    VK_NONAME (FC)
        Reserved 

    VK_PA1 (FD)
        PA1 key

    VK_OEM_CLEAR (FE)
        Clear key
EndRem



Chroma(Posted 2007) [#2]
Under what circumstances did you have windows keyboard input problems? I haven't encountered any at all.


grable(Posted 2007) [#3]
Under what circumstances did you have windows keyboard input problems? I haven't encountered any at all.

GetAsyncKeyState and the like works practically anywhere within a windows app, you cant say the same about BRL.PolledInput