Difference between revisions of "IsKeyPressed2"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>DragoonWraith
(DX scancode list)
imported>Tekuromoto
(another key-trapping code example)
 
(7 intermediate revisions by 5 users not shown)
Line 7: Line 7:


DirectX scancodes are typically in hexadecimal, but this function takes decimal values.
DirectX scancodes are typically in hexadecimal, but this function takes decimal values.
==Sample Key DX Scancodes==
<pre>
Hex  Dec  Button
0x01    1  Escape
0x02    2  1
0x03    3  2
0x04    4  3
...
0x09    9  8
0x0A  10  9
0x0B  11  0
---
0x10  16  Q
0x11  17  W
0x12  18  E
...
0x17  23  I
0x18  24  O
0x19  25  P
---
0x1C  28  Enter
0x1D  29  Left Control
---
0x1E  30  A
0x1F  31  S
0x20  32  D
...
0x24  36  J
0x25  37  K
0x26  38  L
---
0x2A  42  Left Shift
---
0x2C  44  Z
0x2D  45  X
0x2E  46  C
...
0x30  47  B
0x31  48  N
0x32  49  M
---
0x36  54  Right Shift
0x37  55  NUM*
0x38  56  Left Alt
0x39  57  Spacebar
0x3A  58  Caps Lock
---
0x3B  59  F1
0x3C  60  F2
0x3D  61  F3
...
0x43  66  F8
0x44  67  F9
0x45  68  F10
---
0x47  70  NUM7
0x48  71  NUM8
0x49  72  NUM9
0x4A  73  NUM-
0x4B  74  NUM4
0x4C  75  NUM5
0x4D  76  NUM6
0x4E  77  NUM+
0x4F  78  NUM1
0x50  79  NUM2
0x51  80  NUM3
0x52  81  NUM0
0x53  82  NUM.
---
0x54  83  F11
0x55  84  F12
---
0x9C  156  NUM Enter
---
0x9D  157  Right Control
---
0xB5  181  NUM/
---
0xB8  184  Right Alt
---
0xC8  200  Up Arrow
0xCB  203  Left Arrow
0xCD  205  Right Arrow
0xD0  208  Down Arrow
</pre>
A longer list can be found [http://www.gamespp.com/directx/directInputKeyboardScanCodes.html here].


==Notes==
==Notes==


* As well as the normal DX scancodes, you can use the numbers 256 to 263 to check for mouse button presses, and also 264 and 265 to check for mouse wheel movement.
* This function will return false if a key which was previously disabled using [[disableKey]] is pressed, but will return true if a mouse button is pressed while that button is disabled.
* This function will return true if the key is "pressed" via [[TapKey]] or [[TapControl]], even if the key has been disabled with [[DisableKey]] or [[DisableControl]]. This is the ''only'' function that can detect tapped keys.
* 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 && isKeyPressed2 curkey ) ; key still being held down
<pre>if ( curKey && isKeyPressed2 curkey ) ; key still being held down
Line 108: Line 24:
   set curKey to <keyCode>
   set curKey to <keyCode>
endif</pre>
endif</pre>
* The following works without using a Return, in case you need code below your keypress block to continue executing on subsequent frames even if the key is still down:
<pre>short MyKey
short KeyDown
if (IsKeyPressed3 MyKey) && (Keydown == 0) ; first frame with key pressed
set Keydown to 1
;
; do stuff, once per keypress...
;
elseif (IsKeyPressed3 MyKey == 0) && Keydown ; wait til key released then toggle flag
set Keydown to 0
endif</pre>
{{DirectX Scancodes}}


==See Also==
==See Also==
*[[IsKeyPressed]]
*[[IsKeyPressed3]]
*[[IsControlPressed]]
*[[OnKeyDown]]
*[[OnControlDown]]


*[[IsKeyPressed]]
<!--[[Category: OBSE Functions]]
[[Category: OBSE Input Functions]]-->


[[Category: OBSE Functions]]
[[Category: Functions]]
[[Category: OBSE Input Functions]]
[[Category: Functions (OBSE)]]
[[Category: Input Functions]]
[[Category: Input Functions (OBSE)]]

Latest revision as of 16:33, 14 May 2009

A command for Oblivion Script Extender

Syntax:

IsKeyPressed2 key

Returns true if key is currently pressed down. Key values are DirectX scancodes, as opposed to IsKeyPressed's Windows header codes.

DirectX scancodes are typically in hexadecimal, but this function takes decimal values.

Notes[edit | edit source]

  • As well as the normal DX scancodes, you can use the numbers 256 to 263 to check for mouse button presses, and also 264 and 265 to check for mouse wheel movement.
  • This function will return false if a key which was previously disabled using disableKey is pressed, but will return true if a mouse button is pressed while that button is disabled.
  • This function will return true if the key is "pressed" via TapKey or TapControl, even if the key has been disabled with DisableKey or DisableControl. This is the only function that can detect tapped keys.
  • 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 && isKeyPressed2 curkey ) ; key still being held down
  return ; wait until it's released
else
  set curkey to 0
endif

if ( isKeyPressed2 <keyCode> )
  ; do stuff
  set curKey to <keyCode>
endif
  • The following works without using a Return, in case you need code below your keypress block to continue executing on subsequent frames even if the key is still down:
short MyKey
short KeyDown

if (IsKeyPressed3 MyKey) && (Keydown == 0) ; first frame with key pressed
	set Keydown to 1
	;
	; do stuff, once per keypress...
	;
elseif (IsKeyPressed3 MyKey == 0) && Keydown ; wait til key released then toggle flag
	set Keydown to 0
endif

Sample DirectX Key Scancodes[edit source]

 Hex  Dec  Button
0x01     1  Escape
0x02     2  1
0x03     3  2
0x04     4  3
0x05     5  4
0x06     6  5
0x07     7  6
0x08     8  7
0x09     9  8
0x0A    10  9
0x0B    11  0
0x0C    12  Minus
0x0D    13  Equals
0x0E    14  Backspace
0x0F    15  Tab
0x10    16  Q
0x11    17  W
0x12    18  E
0x13    19  R
0x14    20  T
0x15    21  Y
0x16    22  U
0x17    23  I
0x18    24  O
0x19    25  P
0x1A    26  Left Bracket
0x1B    27  Right Bracket
0x1C    28  Enter
0x1D    29  Left Control
0x1E    30  A
0x1F    31  S
0x20    32  D
0x21    33  F
0x22    34  G
0x23    35  H
0x24    36  J
0x25    37  K
0x26    38  L
0x27    39  Semicolon
0x28    40  Apostrophe
0x29    41  ~ (Console)
0x2A    42  Left Shift
0x2B    43  Back Slash
0x2C    44  Z
0x2D    45  X
0x2E    46  C
0x2F    47  V
0x30    48  B
0x31    49  N
0x32    50  M
0x33    51  Comma
0x34    52  Period
0x35    53  Forward Slash  
0x36    54  Right Shift
0x37    55  NUM*
0x38    56  Left Alt
0x39    57  Spacebar
0x3A    58  Caps Lock
0x3B    59  F1
0x3C    60  F2
0x3D    61  F3
0x3E    62  F4
0x3F    63  F5
0x40    64  F6
0x41    65  F7
0x42    66  F8
0x43    67  F9
0x44    68  F10
0x45    69  Num Lock
0x46    70  Scroll Lock
0x47    71  NUM7
0x48    72  NUM8
0x49    73  NUM9
0x4A    74  NUM-
0x4B    75  NUM4
0x4C    76  NUM5
0x4D    77  NUM6
0x4E    78  NUM+
0x4F    79  NUM1
0x50    80  NUM2
0x51    81  NUM3
0x52    82  NUM0
0x53    83  NUM.
0x57    87  F11
0x58    88  F12
0x9C   156  NUM Enter
0x9D   157  Right Control
0xB5   181  NUM/
0xB8   184  Right Alt
0xC7   199  Home
0xC8   200  Up Arrow
0xC9   201  PgUp
0xCB   203  Left Arrow
0xCD   205  Right Arrow
0xCF   207  End
0xD0   208  Down Arrow
0xD1   209  PgDown
0xD2   210  Insert
0xD3   211  Delete
0x100  256  Left Mouse Button
0x101  257  Right Mouse Button
0x102  258  Middle/Wheel Mouse Button
0x103  259  Mouse Button 3
0x104  260  Mouse Button 4
0x105  261  Mouse Button 5
0x106  262  Mouse Button 6
0x107  263  Mouse Button 7
0x108  264  Mouse Wheel Up
0x109  265  Mouse Wheel Down

A longer list can be found here A useful tool for getting scancodes: keyview

These can be converted into Virtual Keyboard codes using DX2VK.


See Also[edit | edit source]