IsKeyPressed

Revision as of 10:15, 2 August 2006 by imported>DragoonWraith (function)

A command for Oblivion Script Extender

Syntax:

IsKeyPressed key

Returns true if key is currently pressed down. Key values are stored in Windows header files.

Sample Key IDs

1   Left Mouse Button
2   Right Mouse Button
4   Middle Mouse Button
---
20  Caps Lock
---
32  spacebar
---
48  0
49  1
50  2
...
55  7
56  8
57  9
---
65  A
66  B
67  C
...
88  X
89  Y
90  Z
---
96  NUM0
97  NUM1
98  NUM2
...
103 NUM7
104 NUM8
105 NUM9
106 NUM*
107 NUM+
109 NUM-
111 NUM/
---
112 F1
113 F2
114 F3
...
123 F12
...
127 F16 
---
160 left shift
161 right shift
162 left control
163 right control

A longer list can be found here

Notes

  • This function doesn't return a value while a MessageBox is being displayed, presumably because input is switched over to the MessageBox.
  • Bear in mind that this function returns 1 for as long as the key is held down, so it's generally a good idea to trap the key and then wait until it is released, i.e.:
if ( curKey && isKeyPressed curkey ) ; key still being held down
  return ; wait until it's released
else
  set curkey to 0
endif

if ( isKeyPressed <keyCode> )
  ; do stuff
  set curKey to <keyCode>
endif