feat(event): add ctrl_key and shift_key to LCUI_KeyboardEvent

This commit is contained in:
Liu Chao
2018-07-19 23:16:39 +08:00
parent 4b1f0501f6
commit 6f5f17c2fd
6 changed files with 20 additions and 10 deletions
+8
View File
@@ -68,8 +68,16 @@ typedef struct LCUI_PaintEvent_ {
LCUI_Rect rect;
} LCUI_PaintEvent;
/** The event structure to describe a user interaction with the keyboard */
typedef struct LCUI_KeyboardEvent_ {
/** The virtual-key code of the nonsystem key */
int code;
/** whether the Ctrl key was active when the key event was generated */
LCUI_BOOL ctrl_key;
/** whether the Shift key was active when the key event was generated */
LCUI_BOOL shift_key;
} LCUI_KeyboardEvent;
typedef struct LCUI_MouseMotionEvent_ {
+2
View File
@@ -135,6 +135,8 @@ static void OnKeyboardMessage(LCUI_Event ev, void *arg)
_DEBUG_MSG("keycode: %d, keyscancode: %u, keysym: %lu\n", keysym,
x_ev->xkey.keycode, keysym);
sys_ev.key.code = ConvertKeyCode(keysym);
sys_ev.key.shift_key = x_ev->xkey.state & ShiftMask ? TRUE : FALSE;
sys_ev.key.ctrl_key = x_ev->xkey.state & ControlMask ? TRUE : FALSE;
_DEBUG_MSG("shift: %d, ctrl: %d\n", sys_ev.key.shift_key,
sys_ev.key.ctrl_key);
LCUI_TriggerEvent(&sys_ev, NULL);
+5 -1
View File
@@ -35,10 +35,10 @@
#include <LCUI/ime.h>
using namespace LCUICore;
using namespace Windows::UI;
using namespace Windows::UI::Core;
using namespace Windows::UI::Input;
using namespace Windows::Devices::Input;
using namespace Windows::UI;
using namespace Windows::Foundation;
using namespace Windows::System;
@@ -253,6 +253,8 @@ void InputDriver::OnKeyDown(CoreWindow^ sender, KeyEventArgs^ args)
{
LCUI_SysEventRec ev;
ev.type = LCUI_KEYDOWN;
ev.key.ctrl_key = FALSE;
ev.key.shift_key = FALSE;
ev.key.code = static_cast<int>(args->VirtualKey);
LCUI_TriggerEvent(&ev, NULL);
LCUI_DestroyEvent(&ev);
@@ -262,6 +264,8 @@ void InputDriver::OnKeyUp(CoreWindow^ sender, KeyEventArgs^ args)
{
LCUI_SysEventRec ev;
ev.type = LCUI_KEYUP;
ev.key.ctrl_key = FALSE;
ev.key.shift_key = FALSE;
ev.key.code = static_cast<int>(args->VirtualKey);
LCUI_TriggerEvent(&ev, NULL);
LCUI_DestroyEvent(&ev);
+1 -1
View File
@@ -274,7 +274,7 @@ LCUI_DisplayDriver LCUI_CreateUWPDisplay(void)
driver->endPaint = UWPSurface_EndPaint;
driver->bindEvent = UWPDisplay_BindEvent;
Graph_Init(&display.frame);
display.frame.color_type = COLOR_TYPE_ARGB;
display.frame.color_type = LCUI_COLOR_TYPE_ARGB;
display.surface = NULL;
display.trigger = EventTrigger();
display.is_inited = TRUE;
-5
View File
@@ -60,17 +60,12 @@ static void WinIME_OnChar(LCUI_Event e, void *arg)
LCUIIME_Commit(text, 2);
}
/**
* 输入法被打开时的处理
* 可以在输入法被打开时,初始化相关数据,链接至词库什么的
**/
static LCUI_BOOL IME_Open(void)
{
LCUI_BindSysEvent(WM_CHAR, WinIME_OnChar, NULL, NULL);
return TRUE;
}
/** 输入法被关闭时的处理 */
static LCUI_BOOL IME_Close(void)
{
LCUI_UnbindSysEvent(WM_CHAR, WinIME_OnChar);
+4 -3
View File
@@ -38,19 +38,20 @@
static void OnKeyboardMessage(LCUI_Event ev, void *arg)
{
MSG* msg = arg;
static POINT mouse_pos;
LCUI_SysEventRec sys_ev;
switch (msg->message) {
case WM_KEYDOWN:
sys_ev.type = LCUI_KEYDOWN;
sys_ev.key.code = msg->wParam;
break;
case WM_KEYUP:
sys_ev.type = LCUI_KEYUP;
sys_ev.key.code = msg->wParam;
break;
default: return;
}
sys_ev.key.code = msg->wParam;
sys_ev.key.shift_key = (GetKeyState(VK_SHIFT) & 0x8000) ? TRUE : FALSE;
sys_ev.key.ctrl_key = (GetKeyState(VK_CONTROL) & 0x8000) ? TRUE : FALSE;
LCUI_TriggerEvent(&sys_ev, NULL);
}