Skip to content

Commit

Permalink
fix capslock
Browse files Browse the repository at this point in the history
  • Loading branch information
xianjimli committed Jan 3, 2019
1 parent c2a1280 commit 3f561dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* 密码编辑器增加显示/不显示明文的开关。
* 键盘增加关闭按钮。
* 修改把控件状态改成字符串导致的BUG。
* 修改处理capslock的BUG。

* 2019/01/02
* 整理API文档:input\_method/input\_method\_default/input\_method\_sdl/input\_method\_null
Expand Down
14 changes: 10 additions & 4 deletions src/base/input_device_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ static ret_t input_device_status_update_key_status(input_device_status_t* ids, u
ids->ctrl = down;
}

if (key == TK_KEY_CAPSLOCK) {
ids->capslock = down;
if (!down) {
if (key == TK_KEY_CAPSLOCK) {
ids->capslock = !(ids->capslock);
}
}

return RET_OK;
Expand Down Expand Up @@ -77,12 +79,16 @@ static ret_t input_device_status_shift_key(input_device_status_t* ids, key_event
}

if (ids->shift && ids->capslock) {
if (c >= 'A' && c <= 'Z') {
e->key = tolower(c);
}

return RET_OK;
}

if (ids->shift || ids->capslock) {
if (c >= TK_KEY_a && c <= TK_KEY_z) {
e->key = c - 32;
if (c >= 'a' && c <= 'z') {
e->key = toupper(c);
}
}

Expand Down
13 changes: 12 additions & 1 deletion tests/input_device_status_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,25 @@ TEST(InputDeviceStatus, capslock) {
e.key = TK_KEY_CAPSLOCK;
e.e = event_init(EVT_KEY_DOWN, NULL);
input_device_status_on_input_event(ids, w, (event_t*)(&e));
ASSERT_EQ(s_log, "keydown");

e.e = event_init(EVT_KEY_UP, NULL);
input_device_status_on_input_event(ids, w, (event_t*)(&e));
ASSERT_EQ(s_log, "keyup");

ASSERT_EQ(ids->capslock, TRUE);

e.key = TK_KEY_CAPSLOCK;
e.e = event_init(EVT_KEY_DOWN, NULL);
input_device_status_on_input_event(ids, w, (event_t*)(&e));
ASSERT_EQ(s_log, "keydown");

e.e = event_init(EVT_KEY_UP, NULL);
input_device_status_on_input_event(ids, w, (event_t*)(&e));
ASSERT_EQ(ids->capslock, FALSE);
ASSERT_EQ(s_log, "keyup");

ASSERT_EQ(ids->capslock, FALSE);

widget_destroy(w);
}

Expand Down

0 comments on commit 3f561dc

Please sign in to comment.