more keyboard function (is down)

This commit is contained in:
Patedam committed 2026-10-25 20:49:27 -04:00
1 parent dec8cbd059
commit 17af5348e9
3 files changed
+118

No files matched your search

@@ -216,6 +216,111 @@ internal WM_Key w32_wm_os_key_from_vkey(WPARAM vKey)
return key;
}
internal WPARAM w32_wm_vkey_from_os_key(WM_Key key)
{
WPARAM result = 0;
{
local_persist bool32 initialized = 0;
local_persist WPARAM vkey_table[WM_Key_COUNT] = { 0 };
if (initialized == 0)
{
initialized = 1;
vkey_table[WM_Key_Esc] = VK_ESCAPE;
for (WM_Key key = WM_Key_F1; key <= WM_Key_F24; key = (WM_Key)(key + 1))
{
vkey_table[key] = VK_F1 + (key - WM_Key_F1);
}
vkey_table[WM_Key_Tick] = VK_OEM_3;
for (WM_Key key = WM_Key_0; key <= WM_Key_9; key = (WM_Key)(key + 1))
{
vkey_table[key] = '0' + (key - WM_Key_0);
}
vkey_table[WM_Key_Minus] = VK_OEM_MINUS;
vkey_table[WM_Key_Equal] = VK_OEM_PLUS;
vkey_table[WM_Key_Backspace] = VK_BACK;
vkey_table[WM_Key_Tab] = VK_TAB;
vkey_table[WM_Key_Q] = 'Q';
vkey_table[WM_Key_W] = 'W';
vkey_table[WM_Key_E] = 'E';
vkey_table[WM_Key_R] = 'R';
vkey_table[WM_Key_T] = 'T';
vkey_table[WM_Key_Y] = 'Y';
vkey_table[WM_Key_U] = 'U';
vkey_table[WM_Key_I] = 'I';
vkey_table[WM_Key_O] = 'O';
vkey_table[WM_Key_P] = 'P';
vkey_table[WM_Key_LeftBracket] = VK_OEM_4;
vkey_table[WM_Key_RightBracket] = VK_OEM_6;
vkey_table[WM_Key_BackSlash] = VK_OEM_5;
vkey_table[WM_Key_CapsLock] = VK_CAPITAL;
vkey_table[WM_Key_A] = 'A';
vkey_table[WM_Key_S] = 'S';
vkey_table[WM_Key_D] = 'D';
vkey_table[WM_Key_F] = 'F';
vkey_table[WM_Key_G] = 'G';
vkey_table[WM_Key_H] = 'H';
vkey_table[WM_Key_J] = 'J';
vkey_table[WM_Key_K] = 'K';
vkey_table[WM_Key_L] = 'L';
vkey_table[WM_Key_Semicolon] = VK_OEM_1;
vkey_table[WM_Key_Quote] = VK_OEM_7;
vkey_table[WM_Key_Return] = VK_RETURN;
vkey_table[WM_Key_Shift] = VK_SHIFT;
vkey_table[WM_Key_Z] = 'Z';
vkey_table[WM_Key_X] = 'X';
vkey_table[WM_Key_C] = 'C';
vkey_table[WM_Key_V] = 'V';
vkey_table[WM_Key_B] = 'B';
vkey_table[WM_Key_N] = 'N';
vkey_table[WM_Key_M] = 'M';
vkey_table[WM_Key_Comma] = VK_OEM_COMMA;
vkey_table[WM_Key_Period] = VK_OEM_PERIOD;
vkey_table[WM_Key_Slash] = VK_OEM_2;
vkey_table[WM_Key_Ctrl] = VK_CONTROL;
vkey_table[WM_Key_Alt] = VK_MENU;
vkey_table[WM_Key_Space] = VK_SPACE;
vkey_table[WM_Key_Menu] = VK_APPS;
vkey_table[WM_Key_ScrollLock] = VK_SCROLL;
vkey_table[WM_Key_Pause] = VK_PAUSE;
vkey_table[WM_Key_Insert] = VK_INSERT;
vkey_table[WM_Key_Home] = VK_HOME;
vkey_table[WM_Key_PageUp] = VK_PRIOR;
vkey_table[WM_Key_Delete] = VK_DELETE;
vkey_table[WM_Key_End] = VK_END;
vkey_table[WM_Key_PageDown] = VK_NEXT;
vkey_table[WM_Key_Up] = VK_UP;
vkey_table[WM_Key_Left] = VK_LEFT;
vkey_table[WM_Key_Down] = VK_DOWN;
vkey_table[WM_Key_Right] = VK_RIGHT;
for (WM_Key key = WM_Key_Ex0; key <= WM_Key_Ex29; key = (WM_Key)(key + 1))
{
vkey_table[key] = 0xDF + (key - WM_Key_Ex0);
}
vkey_table[WM_Key_NumLock] = VK_NUMLOCK;
vkey_table[WM_Key_NumSlash] = VK_DIVIDE;
vkey_table[WM_Key_NumStar] = VK_MULTIPLY;
vkey_table[WM_Key_NumMinus] = VK_SUBTRACT;
vkey_table[WM_Key_NumPlus] = VK_ADD;
vkey_table[WM_Key_NumPeriod] = VK_DECIMAL;
vkey_table[WM_Key_Num0] = VK_NUMPAD0;
vkey_table[WM_Key_Num1] = VK_NUMPAD1;
vkey_table[WM_Key_Num2] = VK_NUMPAD2;
vkey_table[WM_Key_Num3] = VK_NUMPAD3;
vkey_table[WM_Key_Num4] = VK_NUMPAD4;
vkey_table[WM_Key_Num5] = VK_NUMPAD5;
vkey_table[WM_Key_Num6] = VK_NUMPAD6;
vkey_table[WM_Key_Num7] = VK_NUMPAD7;
vkey_table[WM_Key_Num8] = VK_NUMPAD8;
vkey_table[WM_Key_Num9] = VK_NUMPAD9;
vkey_table[WM_Key_LeftMouseButton] = VK_LBUTTON;
vkey_table[WM_Key_MiddleMouseButton] = VK_MBUTTON;
vkey_table[WM_Key_RightMouseButton] = VK_RBUTTON;
}
result = vkey_table[key];
}
return result;
}
// =============================================================================
// w32 windows proc
@@ -904,6 +1009,17 @@ internal WM_Modifiers wm_get_modifiers()
return modifiers;
}
internal bool32 wm_key_is_down(WM_Key key)
{
bool32 down = 0;
WPARAM vkey = w32_wm_vkey_from_os_key(key);
if (GetKeyState(vkey) & 0x8000)
{
down = 1;
}
return down;
}
internal Vector2f wm_mouse_from_window(WM_Window handle)
{
Vector2f result = { 0 };
@@ -88,6 +88,7 @@ internal W32_WM_Window* w32_wm_window_alloc(HWND hwnd);
internal void w32_wm_window_release(W32_WM_Window* window);
internal WM_Event* w32_wm_push_event(WM_EventKind kind, W32_WM_Window* window);
internal WM_Key w32_wm_os_key_from_vkey(WPARAM vKey);
internal WPARAM w32_wm_vkey_from_os_key(WM_Key key);
internal LRESULT w32_wm_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// =============================================================================
+1
View File
@@ -153,6 +153,7 @@ internal float32 wm_dpi_from_monitor(WM_Monitor monitor);
internal void wm_send_wakeup_event();
internal WM_EventList wm_get_events(Arena* arena, bool32 wait);
internal WM_Modifiers wm_get_modifiers();
internal bool32 wm_key_is_down(WM_Key key);
internal Vector2f wm_mouse_from_window(WM_Window window);
// =============================================================================