Skip to content

Commit 6f5f17c

Browse files
committed
feat(event): add ctrl_key and shift_key to LCUI_KeyboardEvent
1 parent 4b1f050 commit 6f5f17c

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

include/LCUI/main.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,16 @@ typedef struct LCUI_PaintEvent_ {
6868
LCUI_Rect rect;
6969
} LCUI_PaintEvent;
7070

71+
/** The event structure to describe a user interaction with the keyboard */
7172
typedef struct LCUI_KeyboardEvent_ {
73+
/** The virtual-key code of the nonsystem key */
7274
int code;
75+
76+
/** whether the Ctrl key was active when the key event was generated */
77+
LCUI_BOOL ctrl_key;
78+
79+
/** whether the Shift key was active when the key event was generated */
80+
LCUI_BOOL shift_key;
7381
} LCUI_KeyboardEvent;
7482

7583
typedef struct LCUI_MouseMotionEvent_ {

src/platform/linux/linux_x11keyboard.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ static void OnKeyboardMessage(LCUI_Event ev, void *arg)
135135
_DEBUG_MSG("keycode: %d, keyscancode: %u, keysym: %lu\n", keysym,
136136
x_ev->xkey.keycode, keysym);
137137
sys_ev.key.code = ConvertKeyCode(keysym);
138+
sys_ev.key.shift_key = x_ev->xkey.state & ShiftMask ? TRUE : FALSE;
139+
sys_ev.key.ctrl_key = x_ev->xkey.state & ControlMask ? TRUE : FALSE;
138140
_DEBUG_MSG("shift: %d, ctrl: %d\n", sys_ev.key.shift_key,
139141
sys_ev.key.ctrl_key);
140142
LCUI_TriggerEvent(&sys_ev, NULL);

src/platform/windows/uwp_input.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
#include <LCUI/ime.h>
3636

3737
using namespace LCUICore;
38+
using namespace Windows::UI;
3839
using namespace Windows::UI::Core;
3940
using namespace Windows::UI::Input;
4041
using namespace Windows::Devices::Input;
41-
using namespace Windows::UI;
4242
using namespace Windows::Foundation;
4343
using namespace Windows::System;
4444

@@ -253,6 +253,8 @@ void InputDriver::OnKeyDown(CoreWindow^ sender, KeyEventArgs^ args)
253253
{
254254
LCUI_SysEventRec ev;
255255
ev.type = LCUI_KEYDOWN;
256+
ev.key.ctrl_key = FALSE;
257+
ev.key.shift_key = FALSE;
256258
ev.key.code = static_cast<int>(args->VirtualKey);
257259
LCUI_TriggerEvent(&ev, NULL);
258260
LCUI_DestroyEvent(&ev);
@@ -262,6 +264,8 @@ void InputDriver::OnKeyUp(CoreWindow^ sender, KeyEventArgs^ args)
262264
{
263265
LCUI_SysEventRec ev;
264266
ev.type = LCUI_KEYUP;
267+
ev.key.ctrl_key = FALSE;
268+
ev.key.shift_key = FALSE;
265269
ev.key.code = static_cast<int>(args->VirtualKey);
266270
LCUI_TriggerEvent(&ev, NULL);
267271
LCUI_DestroyEvent(&ev);

src/platform/windows/uwp_renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ LCUI_DisplayDriver LCUI_CreateUWPDisplay(void)
274274
driver->endPaint = UWPSurface_EndPaint;
275275
driver->bindEvent = UWPDisplay_BindEvent;
276276
Graph_Init(&display.frame);
277-
display.frame.color_type = COLOR_TYPE_ARGB;
277+
display.frame.color_type = LCUI_COLOR_TYPE_ARGB;
278278
display.surface = NULL;
279279
display.trigger = EventTrigger();
280280
display.is_inited = TRUE;

src/platform/windows/windows_ime.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,12 @@ static void WinIME_OnChar(LCUI_Event e, void *arg)
6060
LCUIIME_Commit(text, 2);
6161
}
6262

63-
/**
64-
* 输入法被打开时的处理
65-
* 可以在输入法被打开时,初始化相关数据,链接至词库什么的
66-
**/
6763
static LCUI_BOOL IME_Open(void)
6864
{
6965
LCUI_BindSysEvent(WM_CHAR, WinIME_OnChar, NULL, NULL);
7066
return TRUE;
7167
}
7268

73-
/** 输入法被关闭时的处理 */
7469
static LCUI_BOOL IME_Close(void)
7570
{
7671
LCUI_UnbindSysEvent(WM_CHAR, WinIME_OnChar);

src/platform/windows/windows_keyboard.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@
3838
static void OnKeyboardMessage(LCUI_Event ev, void *arg)
3939
{
4040
MSG* msg = arg;
41-
static POINT mouse_pos;
4241
LCUI_SysEventRec sys_ev;
42+
4343
switch (msg->message) {
4444
case WM_KEYDOWN:
4545
sys_ev.type = LCUI_KEYDOWN;
46-
sys_ev.key.code = msg->wParam;
4746
break;
4847
case WM_KEYUP:
4948
sys_ev.type = LCUI_KEYUP;
50-
sys_ev.key.code = msg->wParam;
5149
break;
5250
default: return;
5351
}
52+
sys_ev.key.code = msg->wParam;
53+
sys_ev.key.shift_key = (GetKeyState(VK_SHIFT) & 0x8000) ? TRUE : FALSE;
54+
sys_ev.key.ctrl_key = (GetKeyState(VK_CONTROL) & 0x8000) ? TRUE : FALSE;
5455
LCUI_TriggerEvent(&sys_ev, NULL);
5556
}
5657

0 commit comments

Comments
 (0)