Difference between revisions of "IsKeyPressed"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Scruggs
(returns true over multiple frames)
imported>QQuix
(Replaced dead link)
 
(25 intermediate revisions by 9 users not shown)
Line 4: Line 4:
  IsKeyPressed key
  IsKeyPressed key


Returns true if key is currently pressed down. Key values are stored in Windows header files.
Returns true if key is currently pressed down. Key values are stored in Windows header files, as opposed to [[IsKeyPressed2]]'s DirectX scancodes.
 
'''Deprecated from OBSE v0013: replaced by [[IsKeyPressed3]] which uses the DX scan codes like the other input functions.'''
 
'''WARNNING!''' Some players have had issues with this. The Iskeypressed uses a different way to monitor the keys than most other similar commands. So they will use different KEY IDS. The B Button for example:
 
Iskeypressed key ID is 66
 
Iskeypressed3 key ID is 48
 
If you are a player and you use the wrong Key ID to set what ever mod you are using your mod will not work properly. Be sure you use the correct KEY ID, read your mod's read me file carefully to determine this.
 


==Sample Key IDs==
==Sample Key IDs==
Line 11: Line 22:
2  Right Mouse Button
2  Right Mouse Button
4  Middle Mouse Button
4  Middle Mouse Button
---
13  Enter
---
---
20  Caps Lock
20  Caps Lock
---
---
32  spacebar
32  spacebar
---
33  PgUp
34  PgDn
35  End
36  Home
37  Left
38  Up
39  Right
40  Down
44  PrtScr
45  Ins
46  Del
---
---
48  0
48  0
Line 57: Line 82:
163 right control
163 right control
</pre>
</pre>
A longer list can be found [http://www.tronan.com/macromachine/scripthelp/VK.htm here]
A longer list can be found [http://msdn.microsoft.com/en-us/library/dd375731(VS.85).aspx here]
 
These can be converted to DirectX keycodes using [[DX2VK]].


==Notes==
==Notes==
* This function doesn't return a value while a [[MessageBox]] is being displayed, presumably because input is switched over to the MessageBox.
* This function doesn't return a value while a [[MessageBox]] is being displayed, presumably because input is switched over to the MessageBox.
* To convert DX scan codes to values usable by this function, use [[DX2VK]].
* 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.:
* 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.:
<pre>if ( curKey && isKeyPressed curkey ) ; key still being held down
<pre>if ( curKey && isKeyPressed curkey ) ; key still being held down
Line 73: Line 100:
   set curKey to <keyCode>
   set curKey to <keyCode>
endif</pre>
endif</pre>
* This function won't work correctly under Windows 2000 unless the .ini setting '''bBackground Keyboard:Controls''' is set to 1. You can use [[con_SetINISetting]] to do this (make sure to set it whenever the game is loaded).
* Will not detect keys force-pressed with [[TapKey]] or [[TapControl]] but will detect disabled keys.
* This is the only input function that detects mouse button presses before the game engine does.
==See Also==
*[[IsKeyPressed2]]
*[[IsKeyPressed3]]
*[[IsControlPressed]]
*[[OnKeyDown]]
*[[OnControlDown]]


[[Category: Oblivion Script Extender]]
[[Category: Functions]]
[[Category: Functions (OBSE)]]
[[Category: Input Functions]]
[[Category: Input Functions (OBSE)]]

Latest revision as of 17:56, 30 May 2012

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, as opposed to IsKeyPressed2's DirectX scancodes.

Deprecated from OBSE v0013: replaced by IsKeyPressed3 which uses the DX scan codes like the other input functions.

WARNNING! Some players have had issues with this. The Iskeypressed uses a different way to monitor the keys than most other similar commands. So they will use different KEY IDS. The B Button for example:

Iskeypressed key ID is 66

Iskeypressed3 key ID is 48

If you are a player and you use the wrong Key ID to set what ever mod you are using your mod will not work properly. Be sure you use the correct KEY ID, read your mod's read me file carefully to determine this.


Sample Key IDs[edit | edit source]

1   Left Mouse Button
2   Right Mouse Button
4   Middle Mouse Button
---
13  Enter
---
20  Caps Lock
---
32  spacebar
---
33  PgUp
34  PgDn
35  End
36  Home
37  Left
38  Up
39  Right
40  Down
44  PrtScr
45  Ins
46  Del
---
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

These can be converted to DirectX keycodes using DX2VK.

Notes[edit | edit source]

  • This function doesn't return a value while a MessageBox is being displayed, presumably because input is switched over to the MessageBox.
  • To convert DX scan codes to values usable by this function, use DX2VK.
  • 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
  • This function won't work correctly under Windows 2000 unless the .ini setting bBackground Keyboard:Controls is set to 1. You can use con_SetINISetting to do this (make sure to set it whenever the game is loaded).
  • Will not detect keys force-pressed with TapKey or TapControl but will detect disabled keys.
  • This is the only input function that detects mouse button presses before the game engine does.

See Also[edit | edit source]