- Joined
- Jul 18, 2010
- Messages
- 2,379
Introduction
With 1.31 Blizzard provided the feature to listen to keyboard presses and releases outside of arrowkeys and ESC. This feature is used over a new Event that can be registered to a trigger.
Simple usage
This is a small Lua example: a trigger runs when player red presses the A key then "A" is printed to the screen.
Lua:
function Test()
local trigger = CreateTrigger()
BlzTriggerRegisterPlayerKeyEvent(trigger, Player(0), OSKEY_A, 0, true)
TriggerAddAction(trigger, function()
print("A")
end)
end)
BlzTriggerRegisterPlayerKeyEvent
The new event is created/registered with
whichPlayer is the player which keyboard is listened, that player can start this new created event.
key is a new type insert in Warcraft 3 V1.31 (See List below)
keyDown decides if that event fires when pressing(true) or when releasing(false) the key.
metaKey it is an integer but it is used as a bitfield. MetaKeys are "none"(0), "shift"(1), "control"(2), "alt"(4) and "META"(8) (windows key).
This MetaKeys can be combinded for example combining control and alt: 2 + 4 = 6. When the user holds control and alt and presses a oskey the event will only run when it was registered with metakey 6.
Inside the press event MetaKey-Keys always have the metakey they start themself or a bigger one if other MetaKeys are hold down during that process.
When holding down all Metakeys the result would be 1 + 2 + 4 + 8 = 15
The metakey used in that event
Is this a press or release event?
The player pressing/releasing the key
When the keyevent fires you can use some getter natives to know what started this event:
The oskeytype table:
OSKEY_SHIFT, OSKEY_CONTROL, OSKEY_ALT can not evoke an keyevent use OSKEY_LSHIFT, OSKEY_LCONTROL, OSKEY_LALT, OSKEY_LMETA instead.
The numbers inside the oskeytype constants like $08 are hexadecimal numbers.
BlzTriggerRegisterPlayerKeyEvent
JASS:
native BlzTriggerRegisterPlayerKeyEvent takes trigger whichTrigger, player whichPlayer, oskeytype key, integer metaKey, boolean keyDown returns event
BlzTriggerRegisterPlayerKeyEvent
takes quite some arguments. Lets take a closer look onto them.whichPlayer is the player which keyboard is listened, that player can start this new created event.
key is a new type insert in Warcraft 3 V1.31 (See List below)
type oskeytype extends handle
constant native ConvertOsKeyType takes integer i returns oskeytype
keyDown decides if that event fires when pressing(true) or when releasing(false) the key.
metaKey it is an integer but it is used as a bitfield. MetaKeys are "none"(0), "shift"(1), "control"(2), "alt"(4) and "META"(8) (windows key).
This MetaKeys can be combinded for example combining control and alt: 2 + 4 = 6. When the user holds control and alt and presses a oskey the event will only run when it was registered with metakey 6.
Inside the press event MetaKey-Keys always have the metakey they start themself or a bigger one if other MetaKeys are hold down during that process.
When holding down all Metakeys the result would be 1 + 2 + 4 + 8 = 15
The metakey used in that event
BlzGetTriggerPlayerIsKeyDown takes nothing returns boolean
Is this a press or release event?
GetTriggerPlayer takes nothing returns player
The player pressing/releasing the key
When the keyevent fires you can use some getter natives to know what started this event:
The oskey firing the event | BlzGetTriggerPlayerKey takes nothing returns oskeytype |
The metakey used in that event | BlzGetTriggerPlayerMetaKey takes nothing returns integer |
Is this a press or release event? | BlzGetTriggerPlayerIsKeyDown takes nothing returns boolean |
The player pressing/releasing the key | GetTriggerPlayer takes nothing returns player |
The oskeytype table:
OSKEY_SHIFT, OSKEY_CONTROL, OSKEY_ALT can not evoke an keyevent use OSKEY_LSHIFT, OSKEY_LCONTROL, OSKEY_LALT, OSKEY_LMETA instead.
The numbers inside the oskeytype constants like $08 are hexadecimal numbers.
JASS:
constant oskeytype OSKEY_BACKSPACE = ConvertOsKeyType($08)
constant oskeytype OSKEY_TAB = ConvertOsKeyType($09)
constant oskeytype OSKEY_CLEAR = ConvertOsKeyType($0C)
constant oskeytype OSKEY_RETURN = ConvertOsKeyType($0D)
constant oskeytype OSKEY_SHIFT = ConvertOsKeyType($10)
constant oskeytype OSKEY_CONTROL = ConvertOsKeyType($11)
constant oskeytype OSKEY_ALT = ConvertOsKeyType($12)
constant oskeytype OSKEY_PAUSE = ConvertOsKeyType($13)
constant oskeytype OSKEY_CAPSLOCK = ConvertOsKeyType($14)
constant oskeytype OSKEY_KANA = ConvertOsKeyType($15)
constant oskeytype OSKEY_HANGUL = ConvertOsKeyType($15)
constant oskeytype OSKEY_JUNJA = ConvertOsKeyType($17)
constant oskeytype OSKEY_FINAL = ConvertOsKeyType($18)
constant oskeytype OSKEY_HANJA = ConvertOsKeyType($19)
constant oskeytype OSKEY_KANJI = ConvertOsKeyType($19)
constant oskeytype OSKEY_ESCAPE = ConvertOsKeyType($1B)
constant oskeytype OSKEY_CONVERT = ConvertOsKeyType($1C)
constant oskeytype OSKEY_NONCONVERT = ConvertOsKeyType($1D)
constant oskeytype OSKEY_ACCEPT = ConvertOsKeyType($1E)
constant oskeytype OSKEY_MODECHANGE = ConvertOsKeyType($1F)
constant oskeytype OSKEY_SPACE = ConvertOsKeyType($20)
constant oskeytype OSKEY_PAGEUP = ConvertOsKeyType($21)
constant oskeytype OSKEY_PAGEDOWN = ConvertOsKeyType($22)
constant oskeytype OSKEY_END = ConvertOsKeyType($23)
constant oskeytype OSKEY_HOME = ConvertOsKeyType($24)
constant oskeytype OSKEY_LEFT = ConvertOsKeyType($25)
constant oskeytype OSKEY_UP = ConvertOsKeyType($26)
constant oskeytype OSKEY_RIGHT = ConvertOsKeyType($27)
constant oskeytype OSKEY_DOWN = ConvertOsKeyType($28)
constant oskeytype OSKEY_SELECT = ConvertOsKeyType($29)
constant oskeytype OSKEY_PRINT = ConvertOsKeyType($2A)
constant oskeytype OSKEY_EXECUTE = ConvertOsKeyType($2B)
constant oskeytype OSKEY_PRINTSCREEN = ConvertOsKeyType($2C)
constant oskeytype OSKEY_INSERT = ConvertOsKeyType($2D)
constant oskeytype OSKEY_DELETE = ConvertOsKeyType($2E)
constant oskeytype OSKEY_HELP = ConvertOsKeyType($2F)
constant oskeytype OSKEY_0 = ConvertOsKeyType($30)
constant oskeytype OSKEY_1 = ConvertOsKeyType($31)
constant oskeytype OSKEY_2 = ConvertOsKeyType($32)
constant oskeytype OSKEY_3 = ConvertOsKeyType($33)
constant oskeytype OSKEY_4 = ConvertOsKeyType($34)
constant oskeytype OSKEY_5 = ConvertOsKeyType($35)
constant oskeytype OSKEY_6 = ConvertOsKeyType($36)
constant oskeytype OSKEY_7 = ConvertOsKeyType($37)
constant oskeytype OSKEY_8 = ConvertOsKeyType($38)
constant oskeytype OSKEY_9 = ConvertOsKeyType($39)
constant oskeytype OSKEY_A = ConvertOsKeyType($41)
constant oskeytype OSKEY_B = ConvertOsKeyType($42)
constant oskeytype OSKEY_C = ConvertOsKeyType($43)
constant oskeytype OSKEY_D = ConvertOsKeyType($44)
constant oskeytype OSKEY_E = ConvertOsKeyType($45)
constant oskeytype OSKEY_F = ConvertOsKeyType($46)
constant oskeytype OSKEY_G = ConvertOsKeyType($47)
constant oskeytype OSKEY_H = ConvertOsKeyType($48)
constant oskeytype OSKEY_I = ConvertOsKeyType($49)
constant oskeytype OSKEY_J = ConvertOsKeyType($4A)
constant oskeytype OSKEY_K = ConvertOsKeyType($4B)
constant oskeytype OSKEY_L = ConvertOsKeyType($4C)
constant oskeytype OSKEY_M = ConvertOsKeyType($4D)
constant oskeytype OSKEY_N = ConvertOsKeyType($4E)
constant oskeytype OSKEY_O = ConvertOsKeyType($4F)
constant oskeytype OSKEY_P = ConvertOsKeyType($50)
constant oskeytype OSKEY_Q = ConvertOsKeyType($51)
constant oskeytype OSKEY_R = ConvertOsKeyType($52)
constant oskeytype OSKEY_S = ConvertOsKeyType($53)
constant oskeytype OSKEY_T = ConvertOsKeyType($54)
constant oskeytype OSKEY_U = ConvertOsKeyType($55)
constant oskeytype OSKEY_V = ConvertOsKeyType($56)
constant oskeytype OSKEY_W = ConvertOsKeyType($57)
constant oskeytype OSKEY_X = ConvertOsKeyType($58)
constant oskeytype OSKEY_Y = ConvertOsKeyType($59)
constant oskeytype OSKEY_Z = ConvertOsKeyType($5A)
constant oskeytype OSKEY_LMETA = ConvertOsKeyType($5B)
constant oskeytype OSKEY_RMETA = ConvertOsKeyType($5C)
constant oskeytype OSKEY_APPS = ConvertOsKeyType($5D)
constant oskeytype OSKEY_SLEEP = ConvertOsKeyType($5F)
constant oskeytype OSKEY_NUMPAD0 = ConvertOsKeyType($60)
constant oskeytype OSKEY_NUMPAD1 = ConvertOsKeyType($61)
constant oskeytype OSKEY_NUMPAD2 = ConvertOsKeyType($62)
constant oskeytype OSKEY_NUMPAD3 = ConvertOsKeyType($63)
constant oskeytype OSKEY_NUMPAD4 = ConvertOsKeyType($64)
constant oskeytype OSKEY_NUMPAD5 = ConvertOsKeyType($65)
constant oskeytype OSKEY_NUMPAD6 = ConvertOsKeyType($66)
constant oskeytype OSKEY_NUMPAD7 = ConvertOsKeyType($67)
constant oskeytype OSKEY_NUMPAD8 = ConvertOsKeyType($68)
constant oskeytype OSKEY_NUMPAD9 = ConvertOsKeyType($69)
constant oskeytype OSKEY_MULTIPLY = ConvertOsKeyType($6A)
constant oskeytype OSKEY_ADD = ConvertOsKeyType($6B)
constant oskeytype OSKEY_SEPARATOR = ConvertOsKeyType($6C)
constant oskeytype OSKEY_SUBTRACT = ConvertOsKeyType($6D)
constant oskeytype OSKEY_DECIMAL = ConvertOsKeyType($6E)
constant oskeytype OSKEY_DIVIDE = ConvertOsKeyType($6F)
constant oskeytype OSKEY_F1 = ConvertOsKeyType($70)
constant oskeytype OSKEY_F2 = ConvertOsKeyType($71)
constant oskeytype OSKEY_F3 = ConvertOsKeyType($72)
constant oskeytype OSKEY_F4 = ConvertOsKeyType($73)
constant oskeytype OSKEY_F5 = ConvertOsKeyType($74)
constant oskeytype OSKEY_F6 = ConvertOsKeyType($75)
constant oskeytype OSKEY_F7 = ConvertOsKeyType($76)
constant oskeytype OSKEY_F8 = ConvertOsKeyType($77)
constant oskeytype OSKEY_F9 = ConvertOsKeyType($78)
constant oskeytype OSKEY_F10 = ConvertOsKeyType($79)
constant oskeytype OSKEY_F11 = ConvertOsKeyType($7A)
constant oskeytype OSKEY_F12 = ConvertOsKeyType($7B)
constant oskeytype OSKEY_F13 = ConvertOsKeyType($7C)
constant oskeytype OSKEY_F14 = ConvertOsKeyType($7D)
constant oskeytype OSKEY_F15 = ConvertOsKeyType($7E)
constant oskeytype OSKEY_F16 = ConvertOsKeyType($7F)
constant oskeytype OSKEY_F17 = ConvertOsKeyType($80)
constant oskeytype OSKEY_F18 = ConvertOsKeyType($81)
constant oskeytype OSKEY_F19 = ConvertOsKeyType($82)
constant oskeytype OSKEY_F20 = ConvertOsKeyType($83)
constant oskeytype OSKEY_F21 = ConvertOsKeyType($84)
constant oskeytype OSKEY_F22 = ConvertOsKeyType($85)
constant oskeytype OSKEY_F23 = ConvertOsKeyType($86)
constant oskeytype OSKEY_F24 = ConvertOsKeyType($87)
constant oskeytype OSKEY_NUMLOCK = ConvertOsKeyType($90)
constant oskeytype OSKEY_SCROLLLOCK = ConvertOsKeyType($91)
constant oskeytype OSKEY_OEM_NEC_EQUAL = ConvertOsKeyType($92)
constant oskeytype OSKEY_OEM_FJ_JISHO = ConvertOsKeyType($92)
constant oskeytype OSKEY_OEM_FJ_MASSHOU = ConvertOsKeyType($93)
constant oskeytype OSKEY_OEM_FJ_TOUROKU = ConvertOsKeyType($94)
constant oskeytype OSKEY_OEM_FJ_LOYA = ConvertOsKeyType($95)
constant oskeytype OSKEY_OEM_FJ_ROYA = ConvertOsKeyType($96)
constant oskeytype OSKEY_LSHIFT = ConvertOsKeyType($A0)
constant oskeytype OSKEY_RSHIFT = ConvertOsKeyType($A1)
constant oskeytype OSKEY_LCONTROL = ConvertOsKeyType($A2)
constant oskeytype OSKEY_RCONTROL = ConvertOsKeyType($A3)
constant oskeytype OSKEY_LALT = ConvertOsKeyType($A4)
constant oskeytype OSKEY_RALT = ConvertOsKeyType($A5)
constant oskeytype OSKEY_BROWSER_BACK = ConvertOsKeyType($A6)
constant oskeytype OSKEY_BROWSER_FORWARD = ConvertOsKeyType($A7)
constant oskeytype OSKEY_BROWSER_REFRESH = ConvertOsKeyType($A8)
constant oskeytype OSKEY_BROWSER_STOP = ConvertOsKeyType($A9)
constant oskeytype OSKEY_BROWSER_SEARCH = ConvertOsKeyType($AA)
constant oskeytype OSKEY_BROWSER_FAVORITES = ConvertOsKeyType($AB)
constant oskeytype OSKEY_BROWSER_HOME = ConvertOsKeyType($AC)
constant oskeytype OSKEY_VOLUME_MUTE = ConvertOsKeyType($AD)
constant oskeytype OSKEY_VOLUME_DOWN = ConvertOsKeyType($AE)
constant oskeytype OSKEY_VOLUME_UP = ConvertOsKeyType($AF)
constant oskeytype OSKEY_MEDIA_NEXT_TRACK = ConvertOsKeyType($B0)
constant oskeytype OSKEY_MEDIA_PREV_TRACK = ConvertOsKeyType($B1)
constant oskeytype OSKEY_MEDIA_STOP = ConvertOsKeyType($B2)
constant oskeytype OSKEY_MEDIA_PLAY_PAUSE = ConvertOsKeyType($B3)
constant oskeytype OSKEY_LAUNCH_MAIL = ConvertOsKeyType($B4)
constant oskeytype OSKEY_LAUNCH_MEDIA_SELECT = ConvertOsKeyType($B5)
constant oskeytype OSKEY_LAUNCH_APP1 = ConvertOsKeyType($B6)
constant oskeytype OSKEY_LAUNCH_APP2 = ConvertOsKeyType($B7)
constant oskeytype OSKEY_OEM_1 = ConvertOsKeyType($BA)
constant oskeytype OSKEY_OEM_PLUS = ConvertOsKeyType($BB)
constant oskeytype OSKEY_OEM_COMMA = ConvertOsKeyType($BC)
constant oskeytype OSKEY_OEM_MINUS = ConvertOsKeyType($BD)
constant oskeytype OSKEY_OEM_PERIOD = ConvertOsKeyType($BE)
constant oskeytype OSKEY_OEM_2 = ConvertOsKeyType($BF)
constant oskeytype OSKEY_OEM_3 = ConvertOsKeyType($C0)
constant oskeytype OSKEY_OEM_4 = ConvertOsKeyType($DB)
constant oskeytype OSKEY_OEM_5 = ConvertOsKeyType($DC)
constant oskeytype OSKEY_OEM_6 = ConvertOsKeyType($DD)
constant oskeytype OSKEY_OEM_7 = ConvertOsKeyType($DE)
constant oskeytype OSKEY_OEM_8 = ConvertOsKeyType($DF)
constant oskeytype OSKEY_OEM_AX = ConvertOsKeyType($E1)
constant oskeytype OSKEY_OEM_102 = ConvertOsKeyType($E2)
constant oskeytype OSKEY_ICO_HELP = ConvertOsKeyType($E3)
constant oskeytype OSKEY_ICO_00 = ConvertOsKeyType($E4)
constant oskeytype OSKEY_PROCESSKEY = ConvertOsKeyType($E5)
constant oskeytype OSKEY_ICO_CLEAR = ConvertOsKeyType($E6)
constant oskeytype OSKEY_PACKET = ConvertOsKeyType($E7)
constant oskeytype OSKEY_OEM_RESET = ConvertOsKeyType($E9)
constant oskeytype OSKEY_OEM_JUMP = ConvertOsKeyType($EA)
constant oskeytype OSKEY_OEM_PA1 = ConvertOsKeyType($EB)
constant oskeytype OSKEY_OEM_PA2 = ConvertOsKeyType($EC)
constant oskeytype OSKEY_OEM_PA3 = ConvertOsKeyType($ED)
constant oskeytype OSKEY_OEM_WSCTRL = ConvertOsKeyType($EE)
constant oskeytype OSKEY_OEM_CUSEL = ConvertOsKeyType($EF)
constant oskeytype OSKEY_OEM_ATTN = ConvertOsKeyType($F0)
constant oskeytype OSKEY_OEM_FINISH = ConvertOsKeyType($F1)
constant oskeytype OSKEY_OEM_COPY = ConvertOsKeyType($F2)
constant oskeytype OSKEY_OEM_AUTO = ConvertOsKeyType($F3)
constant oskeytype OSKEY_OEM_ENLW = ConvertOsKeyType($F4)
constant oskeytype OSKEY_OEM_BACKTAB = ConvertOsKeyType($F5)
constant oskeytype OSKEY_ATTN = ConvertOsKeyType($F6)
constant oskeytype OSKEY_CRSEL = ConvertOsKeyType($F7)
constant oskeytype OSKEY_EXSEL = ConvertOsKeyType($F8)
constant oskeytype OSKEY_EREOF = ConvertOsKeyType($F9)
constant oskeytype OSKEY_PLAY = ConvertOsKeyType($FA)
constant oskeytype OSKEY_ZOOM = ConvertOsKeyType($FB)
constant oskeytype OSKEY_NONAME = ConvertOsKeyType($FC)
constant oskeytype OSKEY_PA1 = ConvertOsKeyType($FD)[/INDENT]
constant oskeytype OSKEY_OEM_CLEAR = ConvertOsKeyType($FE)
Keypress Demo
With this Lua script one can test the possible key presses which is also part of the demo map
When an user holds the left mousebutton while the cursor points on playable ground, no oskeyevent will fire. Frames that block the playable ground (Controlstyle "AUTOTRACK" or example "FRAME") which don't keep focus do not disable oskeyevents even when the left mousebutton is hold.
As long a Frame holds focus no oskey event will be sent.
While typing in chat messages no oskey event will fire (kinda a consequenz of the statement above)
The Menus(F10) at top Left also take focus and disabling oskeyevents from that player while he has them open.
Lua:
function Test()
print("Create Keys")
for index = 8,255 do
local trigger = CreateTrigger()
TriggerAddAction(trigger, function()
print("OsKey:",index, "meta",BlzGetTriggerPlayerMetaKey())
end)
local key = ConvertOsKeyType(index)
for metaKey = 0,15,1 do
BlzTriggerRegisterPlayerKeyEvent(trigger, Player(0), key, metaKey, true)
BlzTriggerRegisterPlayerKeyEvent(trigger, Player(0), key, metaKey, false)
end
end
print("Done")
end)
When an user holds the left mousebutton while the cursor points on playable ground, no oskeyevent will fire. Frames that block the playable ground (Controlstyle "AUTOTRACK" or example "FRAME") which don't keep focus do not disable oskeyevents even when the left mousebutton is hold.
As long a Frame holds focus no oskey event will be sent.
While typing in chat messages no oskey event will fire (kinda a consequenz of the statement above)
The Menus(F10) at top Left also take focus and disabling oskeyevents from that player while he has them open.
Attachments
Last edited: