-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkbd_helper.h
More file actions
61 lines (51 loc) · 1.54 KB
/
Copy pathkbd_helper.h
File metadata and controls
61 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include "input_keycodes.h"
#include "keyboard_input.h"
static u8 current_modifier = 0;
static u8 special_key = 0;
#ifdef __cplusplus
extern "C" {
#endif
#include "syscalls/syscalls.h"
static inline bool handle_modifier(kbd_event *event){
switch (event->type) {
case MOD_PRESS:
current_modifier |= event->modifier;
return true;
case MOD_RELEASE:
current_modifier &= ~event->modifier;
return true;
case KEY_PRESS:
if (event->key == KEY_CAPSLOCK){
print("Current special key %x",special_key);
if (!special_key)
special_key = event->key;
else if (special_key == KEY_CAPSLOCK)
special_key = 0;
return true;
}
return false;
default: return false;
}
}
static inline bool is_mod_pressed(int mod, bool double_side){
if (double_side && mod < 4 && (current_modifier >> (mod + 4)) & 1) return true;
return (current_modifier >> mod) & 1;
}
static inline bool handle_copy(kbd_event *ev, void (*on_copy)(void *ctx)){
if (current_modifier & KEY_MOD_LMETA && ev->type == KEY_PRESS && ev->key == KEY_C){
on_copy(ev);
return true;
}
return false;
}
static inline bool handle_paste(kbd_event *ev, void (*on_paste)(void *ctx)){
if (current_modifier & KEY_MOD_LMETA && ev->type == KEY_PRESS && ev->key == KEY_V){
on_paste(ev);
return true;
}
return false;
}
#ifdef __cplusplus
}
#endif