Преглед изворни кода

Add support to modifier keys

Daniele Bartolini пре 12 година
родитељ
комит
4d0f0f3dc1
3 измењених фајлова са 23 додато и 16 уклоњено
  1. 3 0
      src/input/InputManager.cpp
  2. 4 3
      src/input/Keyboard.h
  3. 16 13
      src/os/linux/Input.cpp

+ 3 - 0
src/input/InputManager.cpp

@@ -137,6 +137,9 @@ void InputManager::event_loop()
 			{
 				KeyboardEvent keyboard_event;
 				keyboard_event.key = event.data_a.int_value;
+				keyboard_event.modifier = (uint8_t)event.data_b.int_value;
+
+				m_keyboard.m_modifier = keyboard_event.modifier;
 
 				if (event.type == os::OSET_KEY_PRESS)
 				{

+ 4 - 3
src/input/Keyboard.h

@@ -44,8 +44,9 @@ enum ModifierKey
 
 struct KeyboardEvent
 {
-	Key key;
-	char text[4];
+	Key			key;
+	uint8_t		modifier;
+	char		text[4];
 };
 
 class KeyboardListener
@@ -81,7 +82,7 @@ public:
 
 private:
 
-	ModifierKey		m_modifier;
+	uint8_t			m_modifier;
 
 	// True if key pressed, false otherwise.
 	bool			m_keys[MAX_KEYCODES];

+ 16 - 13
src/os/linux/Input.cpp

@@ -241,23 +241,26 @@ void event_loop()
 
 				Key kc = x11_translate_key(key);
 
-//				// Check if any modifier key is pressed or released
-//				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_SHIFT : mModifierMask &= ~MK_SHIFT;
-//				}
-//				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_CTRL : mModifierMask &= ~MK_CTRL;
-//				}
-//				else if (kc == KC_LALT || kc == KC_RALT)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_ALT : mModifierMask &= ~MK_ALT;
-//				}
+				// Check if any modifier key is pressed or released
+				int32_t modifier_mask = 0;
+
+				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
+				{
+					(event.type == KeyPress) ? modifier_mask |= MK_SHIFT : modifier_mask &= ~MK_SHIFT;
+				}
+				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
+				{
+					(event.type == KeyPress) ? modifier_mask |= MK_CTRL : modifier_mask &= ~MK_CTRL;
+				}
+				else if (kc == KC_LALT || kc == KC_RALT)
+				{
+					(event.type == KeyPress) ? modifier_mask |= MK_ALT : modifier_mask &= ~MK_ALT;
+				}
 
 				OSEventType oset_type = event.type == KeyPress ? OSET_KEY_PRESS : OSET_KEY_RELEASE;
 
 				data_key[0].int_value = ((int32_t)kc);
+				data_key[1].int_value = modifier_mask;
 
 				push_event(oset_type, data_key[0], data_key[1], data_key[2], data_key[3]);