Implementing more of the Windows/X11 KeyMap

This commit is contained in:
2024-02-13 20:24:06 -05:00
parent 7e8a1b4030
commit 089b110b87
3 changed files with 50 additions and 18 deletions

View File

@@ -101,9 +101,10 @@ enum class X11Scancode {
F8 = 74,
F9 = 75,
F10 = 76,
F11 = 77,
F12 = 78,
F11 = 95,
F12 = 96,
PRINT = 107,
SCROLL_LOCK = 78,
BREAK = 127,
};

View File

@@ -7,6 +7,7 @@
#include <J3ML/LinearAlgebra/Vector2.h>
#include <stdexcept>
#include <iostream>
#if __linux__
#include <X11/X.h>
@@ -35,6 +36,7 @@ public:
};
namespace Keys {
// TODO: Encode both Uppercase and Lowercase version for each keymap
static const Key Escape {'\b', X11Scancode::ESCAPE, WindowsScancode::ESCAPE};
static const Key F1 {'\u000f', X11Scancode::F1, WindowsScancode::F1};
static const Key F2 {'\u000f', X11Scancode::F2, WindowsScancode::F2};
@@ -49,16 +51,27 @@ namespace Keys {
static const Key F11 {'\u000f', X11Scancode::F11, WindowsScancode::F11};
static const Key F12 {'\u000f', X11Scancode::F12, WindowsScancode::F12};
static const Key NumPad1 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad2 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad3 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad4 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad5 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad6 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad7 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad8 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad9 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad0 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad1 {'\b', X11Scancode::KP_1, WindowsScancode::NUMPAD_ONE};
static const Key NumPad2 {'\b', X11Scancode::KP_2, WindowsScancode::NUMPAD_ONE};
static const Key NumPad3 {'\b', X11Scancode::KP_3, WindowsScancode::NUMPAD_ONE};
static const Key NumPad4 {'\b', X11Scancode::KP_4, WindowsScancode::NUMPAD_ONE};
static const Key NumPad5 {'\b', X11Scancode::KP_5, WindowsScancode::NUMPAD_ONE};
static const Key NumPad6 {'\b', X11Scancode::KP_6, WindowsScancode::NUMPAD_ONE};
static const Key NumPad7 {'\b', X11Scancode::KP_7, WindowsScancode::NUMPAD_ONE};
static const Key NumPad8 {'\b', X11Scancode::KP_8, WindowsScancode::NUMPAD_ONE};
static const Key NumPad9 {'\b', X11Scancode::KP_9, WindowsScancode::NUMPAD_ONE};
static const Key NumPad0 {'\b', X11Scancode::KP_0, WindowsScancode::NUMPAD_ONE};
static const Key One {'1', X11Scancode::ONE, WindowsScancode::ONE};
static const Key Two {'2', X11Scancode::TWO, WindowsScancode::TWO};
static const Key Three {'3', X11Scancode::THREE, WindowsScancode::THREE};
static const Key Four {'4', X11Scancode::FOUR, WindowsScancode::FOUR};
static const Key Five {'5', X11Scancode::FIVE, WindowsScancode::FIVE};
static const Key Six {'6', X11Scancode::SIX, WindowsScancode::SIX};
static const Key Seven {'7', X11Scancode::SEVEN, WindowsScancode::SEVEN};
static const Key Eight {'8', X11Scancode::EIGHT, WindowsScancode::EIGHT};
static const Key Nine {'9', X11Scancode::NINE, WindowsScancode::NINE};
static const Key Zero {'0', X11Scancode::ZERO, WindowsScancode::ZERO};
static const Key Q {'Q', X11Scancode::Q, WindowsScancode::Q};
static const Key W {'W', X11Scancode::W, WindowsScancode::W};
@@ -96,19 +109,35 @@ namespace Keys {
static const Key Period {'.', X11Scancode::PERIOD, WindowsScancode::PERIOD};
static const Key ForwardSlash {'/', X11Scancode::SLASH, WindowsScancode::SLASH};
static const Key BackSlash {'\\', X11Scancode::BACKSLASH, WindowsScancode::BACKSLASH};
static const Key LShift;
static const Key RShift;
static const Key Space {' ', X11Scancode::SPACE, WindowsScancode::SPACE};
static const Key LControl {'\\', X11Scancode::LEFT_CTRL, WindowsScancode::CTRL};
static const Key RControl {'\\', X11Scancode::RIGHT_CONTROL, WindowsScancode::CTRL};
static const Key LAlt {'\\', X11Scancode::LEFT_ALT, WindowsScancode::ALT};
static const Key RAlt {'\\', X11Scancode::RIGHT_ALT, WindowsScancode::ALT};
static const Key LShift {'\\', X11Scancode::LEFT, WindowsScancode::LEFT_ARROW};
static const Key RShift {'\\', X11Scancode::RIGHT, WindowsScancode::RIGHT_ARROW};
// TODO: Get the right character codes for these
static const Key UpArrow {'\u000a', X11Scancode::UP, WindowsScancode::UP_ARROW};
static const Key DownArrow {'\u000a', X11Scancode::DOWN, WindowsScancode::DOWN_ARROW};
static const Key LeftArrow {'\u000a', X11Scancode::LEFT, WindowsScancode::LEFT_ARROW};
static const Key RightArrow {'\u000a', X11Scancode::RIGHT, WindowsScancode::RIGHT_ARROW};
static const Key Super {'\000a', X11Scancode::SUPER, WindowsScancode::Nothing};
static const Key Backspace {'\b', X11Scancode::BACKSPACE, WindowsScancode::BACKSPACE};
static const Key LeftBracket {'[', X11Scancode::OPENING_SQUARE_BRACKET, WindowsScancode::LEFT_BRACKET};
static const Key RightBracket {']', X11Scancode::CLOSING_SQUARE_BRACKET, WindowsScancode::RIGHT_BRACKET};
}
class GamepadButton {};
class MouseButton {};
using LinearAlgebra::Vector2;
class InputService {
public:
@@ -157,7 +186,8 @@ static Key GetKeyFromX11Scancode(X11Scancode code)
if (key.x11ScanCode == code)
return key;
}
throw std::runtime_error("Unavaliable Scancode: " + std::to_string((int)code));
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
return Keys::Space;
}
static Key GetKeyFromWindowsScancode(WindowsScancode code)
{
@@ -165,5 +195,6 @@ static Key GetKeyFromWindowsScancode(WindowsScancode code)
if (key.winScanCode == code)
return key;
}
throw std::runtime_error("Unavaliable Scancode: " + std::to_string((int)code));
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
return Keys::Space;
}

View File

@@ -5,7 +5,7 @@
void KeyDown(const ReWindow::WindowEvents::KeyDownEvent& e)
{
std::cout << e.key.CharCode << " pressed" << std::endl;
//std::cout << e.key.CharCode << " pressed" << std::endl;
}
Vector2 mouse_pos;
@@ -21,7 +21,7 @@ class MyWindow : public ReWindow::RWindow
public:
void OnMouseMove(const ReWindow::MouseMoveEvent& e) override
{
std::cout << "Mouse Moved: " << e.Position << " @ " << std::endl;
//std::cout << "Mouse Moved: " << e.Position << " @ " << std::endl;
}
void OnRefresh(float elapsed) override
{