diff --git a/core/input/keyboard_device.cpp b/core/input/keyboard_device.cpp new file mode 100644 index 000000000..83ef7a65a --- /dev/null +++ b/core/input/keyboard_device.cpp @@ -0,0 +1,3 @@ +#include "keyboard_device.h" + +KeyboardDevice *KeyboardDevice::_instance; diff --git a/core/input/keyboard_device.h b/core/input/keyboard_device.h index 767a4768d..ffda03eaa 100644 --- a/core/input/keyboard_device.h +++ b/core/input/keyboard_device.h @@ -21,21 +21,37 @@ #include "types.h" #include "mapping.h" -template class KeyboardDevice { public: virtual const char* name() = 0; int maple_port() { return _maple_port; } - virtual void keyboard_input(Keycode keycode, bool pressed, int modifier_keys = 0); + void keyboard_character(char c); + std::string get_character_input(); virtual ~KeyboardDevice() {} + static KeyboardDevice *GetInstance() { return _instance; } + protected: - KeyboardDevice(int maple_port) : _maple_port(maple_port), _kb_used(0), _modifier_keys(0) {} - virtual u8 convert_keycode(Keycode keycode) = 0; + KeyboardDevice(int maple_port) : _maple_port(maple_port) { _instance = this; } private: int _maple_port; + std::string char_input; + static KeyboardDevice *_instance; +}; + +template +class KeyboardDeviceTemplate : public KeyboardDevice +{ +public: + virtual void keyboard_input(Keycode keycode, bool pressed, int modifier_keys = 0); + +protected: + KeyboardDeviceTemplate(int maple_port) : KeyboardDevice(maple_port), _kb_used(0), _modifier_keys(0) {} + virtual u8 convert_keycode(Keycode keycode) = 0; + +private: int _modifier_keys; int _kb_used; }; @@ -44,7 +60,7 @@ extern u8 kb_key[6]; // normal keys pressed extern u8 kb_shift; // shift keys pressed (bitmask) template -void KeyboardDevice::keyboard_input(Keycode keycode, bool pressed, int modifier_keys) +void KeyboardDeviceTemplate::keyboard_input(Keycode keycode, bool pressed, int modifier_keys) { u8 dc_keycode = convert_keycode(keycode); if (dc_keycode == 0xE1 || dc_keycode == 0xE5) // SHIFT @@ -94,3 +110,13 @@ void KeyboardDevice::keyboard_input(Keycode keycode, bool pressed, int kb_shift = modifier_keys | _modifier_keys; } } + +inline void KeyboardDevice::keyboard_character(char c) { + char_input.push_back(c); +} + +inline std::string KeyboardDevice::get_character_input() { + std::string input = char_input; + char_input.clear(); + return input; +} diff --git a/core/linux-dist/x11.cpp b/core/linux-dist/x11.cpp index 8c6bb7d78..febb8fd35 100644 --- a/core/linux-dist/x11.cpp +++ b/core/linux-dist/x11.cpp @@ -212,6 +212,14 @@ void input_x11_handle() switch(e.type) { case KeyPress: + { + char buf[2]; + KeySym keysym_return; + int len = XLookupString(&e.xkey, buf, 1, &keysym_return, NULL); + if (len > 0) + x11_keyboard->keyboard_character(buf[0]); + } + /* no break */ case KeyRelease: { if (e.type == KeyRelease && XEventsQueued(display, QueuedAfterReading)) @@ -293,12 +301,26 @@ void input_x11_handle() mouse_gamepad->gamepad_btn_input(e.xbutton.button, e.type == ButtonPress); { u32 button_mask = 0; - if (e.xbutton.button == Button1) // Left button + switch (e.xbutton.button) + { + case Button1: // Left button button_mask = 1 << 2; - else if (e.xbutton.button == Button2) // Middle button + break; + case Button2: // Middle button button_mask = 1 << 3; - else if (e.xbutton.button == Button3) // Right button + break; + case Button3: // Right button button_mask = 1 << 1; + break; + case Button4: // Mouse wheel up + mo_wheel_delta -= 16; + break; + case Button5: // Mouse wheel down + mo_wheel_delta += 16; + break; + default: + break; + } if (button_mask) { diff --git a/core/linux-dist/x11_keyboard.h b/core/linux-dist/x11_keyboard.h index 9ac2036e1..e78717e32 100644 --- a/core/linux-dist/x11_keyboard.h +++ b/core/linux-dist/x11_keyboard.h @@ -3,10 +3,10 @@ #include "input/gamepad_device.h" #include "x11.h" -class X11KeyboardDevice : public KeyboardDevice +class X11KeyboardDevice : public KeyboardDeviceTemplate { public: - X11KeyboardDevice(int maple_port) : KeyboardDevice(maple_port) + X11KeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port) { //04-1D Letter keys A-Z (in alphabetic order) kb_map[KEY_A] = 0x04; diff --git a/core/sdl/sdl_keyboard.h b/core/sdl/sdl_keyboard.h index a89168d0d..d8a99e89c 100644 --- a/core/sdl/sdl_keyboard.h +++ b/core/sdl/sdl_keyboard.h @@ -2,10 +2,10 @@ #include "input/keyboard_device.h" #include "sdl.h" -class SDLKeyboardDevice : public KeyboardDevice +class SDLKeyboardDevice : public KeyboardDeviceTemplate { public: - SDLKeyboardDevice(int maple_port) : KeyboardDevice(maple_port) + SDLKeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port) { //04-1D Letter keys A-Z (in alphabetic order) kb_map[SDLK_a] = 0x04; diff --git a/core/windows/win_keyboard.h b/core/windows/win_keyboard.h index 047da2724..9d45f9654 100644 --- a/core/windows/win_keyboard.h +++ b/core/windows/win_keyboard.h @@ -4,10 +4,10 @@ // Used to differentiate between main enter key and num keypad one #define VK_NUMPAD_RETURN 0x0E -class Win32KeyboardDevice : public KeyboardDevice +class Win32KeyboardDevice : public KeyboardDeviceTemplate { public: - Win32KeyboardDevice(int maple_port) : KeyboardDevice(maple_port) + Win32KeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port) { kb_map['A'] = 0x04; kb_map['B'] = 0x05;