Waits for a specific key to be pressed within timeout period.
WaitForKeyEx (keycodes, timeout)
(s) keycodes a tab-delimited list of up to 100 keys to wait for. See WaitForKey for a list of key codes.
(i) timeout the number of seconds to wait before returning.
(i) position of the selected keystroke, or 0 if none of the specified keys were pressed before the timeout occured.
This function is like WaitForKey, but it allows you specify up to 100 keys to wait for and allows for a timeout. Note: Any items in the list past the first 100 will be silently ignored.
If "keycodes" is a blank string (""), then the keycodes from the most recent use of this function will be used again, which will save the overhead of re-parsing the string.
Specify 0 "timeout" to have the function return immediately without waiting. Specify -1 for no timeout (wait forever).
If one of the specified keys is pressed before the timeout occurs, the function will return the value corresponding to the position in "keycodes" of the key that was pressed. The first key in the list is 1.
If none of the specified keys are pressed before the timeout occurs, the function will return 0.
To enter an Alt, Control, or Shift key combination, precede the desired character with one or more of the following symbols:
Key |
SendKey equivalent |
Alt |
! |
Control |
^ |
Shift |
+ |
keycodes = "{BACKSPACE},{BS},{CLEAR},{DELETE},{DEL},{DOWN},{END},{ENTER}," keycodes = StrCat(keycodes,"{ESC},{F1},{F2},{F3},{F4},{F5},{F6},") keycodes = StrCat(keycodes,"{F7},{F8},{F9},{F10},{F11},{F12},{F13},{F14},") keycodes = StrCat(keycodes,"{F15},{F16},{HELP},{HOME},{INSERT},{INS},{LEFT},") keycodes = StrCat(keycodes,"{PGDN},{PGUP},{PRTSC},{RIGHT},{SPACE},{SP},{TAB},{UP},") keycodes = StrCat(keycodes,"0,1,2,3,4,5,6,7,8,9,`,-,=,[,],\,;,',.,/,") keycodes = StrCat(keycodes,"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z") keycodes = StrReplace(keycodes,",",@TAB) BoxOpen("WaitForKeyEx","Press a key") item = WaitForKeyEX(keycodes,-1) key = ItemExtract(item,keycodes,@TAB) BoxShut() Message("WaitForKeyEx", StrCat("You pressed the '",key,"' key")) Exit