Skip to content

Commit

Permalink
feat(event): add ctrl_key and shift_key to LCUI_KeyboardEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Jul 19, 2018
1 parent 4b1f050 commit 6f5f17c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
8 changes: 8 additions & 0 deletions include/LCUI/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ {
Expand Down
2 changes: 2 additions & 0 deletions src/platform/linux/linux_x11keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/platform/windows/uwp_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/uwp_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/platform/windows/windows_ime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/platform/windows/windows_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 6f5f17c

Please sign in to comment.