## Reading the Keyboard State?

### Reading the Keyboard State?

- blue_max
**Posts:**1319**Joined:**Wed Mar 20, 2019 5:12 am

I'm trying to figure out how to read the keyboard state from XWA's memory. I believe there's an int16 variable at offset 0x08053C0 that stores the last key pressed; but it seems to work after a key is released (?). Instead, I'm trying to capture the equivalent of WM_KEYDOWN (when the key is pressed; but not yet released) while also checking if the Shift, Alt or Ctrl keys were pressed at the same time. Just wondering if this is possible at all.

- blue_max
**Posts:**1319**Joined:**Wed Mar 20, 2019 5:12 am

I should correct myself: upon closer inspection, it looks like variable 0x08053C0 actually responds to WM_KEYDOWN; but WM_KEYUP has no effect.

Also does anyone know how the following keycodes are triggered, or what offset can be read to check these codes?

Also does anyone know how the following keycodes are triggered, or what offset can be read to check these codes?

Code: Select all

```
KeyCode_SHIFT = 0xFD,
KeyCode_CTRL = 0xFE,
KeyCode_ALT = 0xFF,
```

- JeremyaFr
**Posts:**2591**Joined:**Mon Jan 18, 2010 5:52 pm-
**Contact:**

You're right. The variable at address 0x08053C0 contains the pressed key.

The code indicates the key and also if the control, alt, or shift key is pressed.

The code indicates the key and also if the control, alt, or shift key is pressed.

Code: Select all

```
// KeyEnum
enum KeyEnum : unsigned short
{
Key_None = 0,
Key_BACK = 8,
Key_TAB = 9,
Key_RETURN = 13,
Key_ESCAPE = 27,
Key_SPACE = 32,
Key_SHIFT_1 = 33,
Key_SHIFT_APOSTROPHE = 34,
Key_SHIFT_3 = 35,
Key_SHIFT_4 = 36,
Key_SHIFT_5 = 37,
Key_SHIFT_7 = 38,
Key_APOSTROPHE = 39,
Key_SHIFT_9 = 40,
Key_SHIFT_0 = 41,
Key_SHIFT_8 = 42,
Key_SHIFT_EQUALS = 43,
Key_COMMA = 44,
Key_MINUS = 45,
Key_PERIOD = 46,
Key_SLASH = 47,
Key_0 = 48,
Key_1 = 49,
Key_2 = 50,
Key_3 = 51,
Key_4 = 52,
Key_5 = 53,
Key_6 = 54,
Key_7 = 55,
Key_8 = 56,
Key_9 = 57,
Key_SHIFT_SEMICOLON = 58,
Key_SEMICOLON = 59,
Key_SHIFT_COMMA = 60,
Key_EQUALS = 61,
Key_SHIFT_PERIOD = 62,
Key_SHIFT_SLASH = 63,
Key_SHIFT_2 = 64,
Key_SHIFT_A = 65,
Key_SHIFT_B = 66,
Key_SHIFT_C = 67,
Key_SHIFT_D = 68,
Key_SHIFT_E = 69,
Key_SHIFT_F = 70,
Key_SHIFT_G = 71,
Key_SHIFT_H = 72,
Key_SHIFT_I = 73,
Key_SHIFT_J = 74,
Key_SHIFT_K = 75,
Key_SHIFT_L = 76,
Key_SHIFT_M = 77,
Key_SHIFT_N = 78,
Key_SHIFT_O = 79,
Key_SHIFT_P = 80,
Key_SHIFT_Q = 81,
Key_SHIFT_R = 82,
Key_SHIFT_S = 83,
Key_SHIFT_T = 84,
Key_SHIFT_U = 85,
Key_SHIFT_V = 86,
Key_SHIFT_W = 87,
Key_SHIFT_X = 88,
Key_SHIFT_Y = 89,
Key_SHIFT_Z = 90,
Key_LBRACKET = 91,
Key_BACKSLASH = 92,
Key_RBRACKET = 93,
Key_SHIFT_6 = 94,
Key_SHIFT_MINUS = 95,
Key_GRAVE = 96,
Key_A = 97,
Key_B = 98,
Key_C = 99,
Key_D = 100,
Key_E = 101,
Key_F = 102,
Key_G = 103,
Key_H = 104,
Key_I = 105,
Key_J = 106,
Key_K = 107,
Key_L = 108,
Key_M = 109,
Key_N = 110,
Key_O = 111,
Key_P = 112,
Key_Q = 113,
Key_R = 114,
Key_S = 115,
Key_T = 116,
Key_U = 117,
Key_V = 118,
Key_W = 119,
Key_X = 120,
Key_Y = 121,
Key_Z = 122,
Key_SHIFT_LBRACKET = 123,
Key_SHIFT_BACKSLASH = 124,
Key_SHIFT_RBRACKET = 125,
Key_SHIFT_GRAVE = 126,
Key_ALT_A = 128,
Key_ALT_B = 129,
Key_ALT_C = 130,
Key_ALT_D = 131,
Key_ALT_E = 132,
Key_ALT_F = 133,
Key_ALT_G = 134,
Key_ALT_H = 135,
Key_ALT_I = 136,
Key_ALT_J = 137,
Key_ALT_K = 138,
Key_ALT_L = 139,
Key_ALT_M = 140,
Key_ALT_N = 141,
Key_ALT_O = 142,
Key_ALT_P = 143,
Key_ALT_Q = 144,
Key_ALT_R = 145,
Key_ALT_S = 146,
Key_ALT_T = 147,
Key_ALT_U = 148,
Key_ALT_V = 149,
Key_ALT_W = 150,
Key_ALT_X = 151,
Key_ALT_Y = 152,
Key_ALT_Z = 153,
Key_ALT_0 = 154,
Key_ALT_1 = 155,
Key_ALT_2 = 156,
Key_ALT_3 = 157,
Key_ALT_4 = 158,
Key_ALT_5 = 159,
Key_ALT_6 = 160,
Key_ALT_7 = 161,
Key_ALT_8 = 162,
Key_ALT_9 = 163,
Key_LEFT = 164,
Key_RIGHT = 165,
Key_UP = 166,
Key_DOWN = 167,
Key_INSERT = 168,
Key_DELETE = 169,
Key_HOME = 170,
Key_END = 171,
Key_PRIOR = 172,
Key_NEXT = 173,
Key_SYSRQ = 174,
Key_SCROLL = 175,
Key_PAUSE = 176,
Key_CAPITAL = 177,
Key_NUMPAD0 = 178,
Key_NUMPAD1 = 179,
Key_NUMPAD2 = 180,
Key_NUMPAD3 = 181,
Key_NUMPAD4 = 182,
Key_NUMPAD5 = 183,
Key_NUMPAD6 = 184,
Key_NUMPAD7 = 185,
Key_NUMPAD8 = 186,
Key_NUMPAD9 = 187,
Key_NUMLOCK = 188,
Key_DIVIDE = 189,
Key_MULTIPLY = 190,
Key_SUBTRACT = 191,
Key_ADD = 192,
Key_NUMPADENTER = 193,
Key_DECIMAL = 194,
Key_F1 = 195,
Key_F2 = 196,
Key_F3 = 197,
Key_F4 = 198,
Key_F5 = 199,
Key_F6 = 200,
Key_F7 = 201,
Key_F8 = 202,
Key_F9 = 203,
Key_F10 = 204,
Key_F11 = 205,
Key_F12 = 206,
Key_SHIFT_F1 = 207,
Key_SHIFT_F2 = 208,
Key_SHIFT_F3 = 209,
Key_SHIFT_F4 = 210,
Key_SHIFT_F5 = 211,
Key_SHIFT_F6 = 212,
Key_SHIFT_F7 = 213,
Key_SHIFT_F8 = 214,
Key_SHIFT_F9 = 215,
Key_SHIFT_F10 = 216,
Key_SHIFT_F11 = 217,
Key_SHIFT_F12 = 218,
Key_CONTROL_OR_ALT_SYSRQ = 232,
Key_CONTROL_SCROLL = 233,
Key_ALT_GRAVE = 234,
Key_SHIFT_PAUSE = 235,
Key_ALT_NUMPAD6 = 240,
Key_ALT_ADD = 241,
Key_ALT_NUMPAD1 = 242,
Key_ALT_NUMPAD2 = 243,
Key_ALT_NUMPAD3 = 244,
Key_ALT_NUMPAD0 = 245,
Key_ALT_DECIMAL = 246,
Key_ALT_OEM_102 = 249,
Key_ALT_F11 = 250,
Key_ALT_F12 = 251,
Key_SHIFT = 253,
Key_CONTROL = 254,
Key_ALT = 255,
Key_CONTROL_0 = 261,
Key_CONTROL_1 = 262,
Key_CONTROL_2 = 263,
Key_CONTROL_3 = 264,
Key_CONTROL_4 = 265,
Key_CONTROL_5 = 266,
Key_CONTROL_6 = 267,
Key_CONTROL_7 = 268,
Key_CONTROL_8 = 269,
Key_CONTROL_9 = 270,
Key_CONTROL_A = 271,
Key_CONTROL_B = 272,
Key_CONTROL_C = 273,
Key_CONTROL_D = 274,
Key_CONTROL_E = 275,
Key_CONTROL_F = 276,
Key_CONTROL_G = 277,
Key_CONTROL_H = 278,
Key_CONTROL_I = 279,
Key_CONTROL_J = 280,
Key_CONTROL_K = 281,
Key_CONTROL_L = 282,
Key_CONTROL_M = 283,
Key_CONTROL_N = 284,
Key_CONTROL_O = 285,
Key_CONTROL_P = 286,
Key_CONTROL_Q = 287,
Key_CONTROL_R = 288,
Key_CONTROL_S = 289,
Key_CONTROL_T = 290,
Key_CONTROL_U = 291,
Key_CONTROL_V = 292,
Key_CONTROL_W = 293,
Key_CONTROL_X = 294,
Key_CONTROL_Y = 295,
Key_CONTROL_Z = 296,
Key_CONTROL_END = 300,
Key_ALT_PERIOD = 301,
};
```

- blue_max
**Posts:**1319**Joined:**Wed Mar 20, 2019 5:12 am

Thanks Jeremy. Yeah, I noticed there were some Key_SHIFT_* and Key_ALT_* combinations; but there doesn't seem to be a keycode for Shilt/Alt/Ctr+Arrows (or I couldn't find one). Also, when pressing the arrow keys I see the same code regardless of the state of the Shift/Alt/Ctrl keys, so I'm guessing these codes were simply not implemented in XWA.

- JeremyaFr
**Posts:**2591**Joined:**Mon Jan 18, 2010 5:52 pm-
**Contact:**

The states are also in these variables:
To update these variables, you can call this function:

The KeyEnum enum is not implemented for all keys combinaisons.

The conversion from dinput key to KeyEnum is stored in these variables:

Code: Select all

```
// V0x006343DC
dword s_XwaIsControlKeyPressed
// V0x006343E0
dword s_XwaIsShiftKeyPressed
// V0x006343E4
dword s_XwaIsAltKeyPressed
```

Code: Select all

```
// L0042B880
void XwaDIKeyboardUpdateShiftControlAltKeysPressedState( )
```

The KeyEnum enum is not implemented for all keys combinaisons.

The conversion from dinput key to KeyEnum is stored in these variables:

Code: Select all

```
// V0x005B2730
extern Array<KeyEnum,256> s_XwaDInputKeyToKeyId ;
// V0x005B2930
extern Array<KeyEnum,256> s_XwaDInputKeyAndShiftToKeyId ;
// V0x005B2B30
extern Array<KeyEnum,256> s_XwaDInputKeyAndControlToKeyId ;
// V0x005B2D30
extern Array<KeyEnum,256> s_XwaDInputKeyAndAltToKeyId ;
```