-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkbd_helper.h
More file actions
42 lines (35 loc) · 954 Bytes
/
kbd_helper.h
File metadata and controls
42 lines (35 loc) · 954 Bytes
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
#pragma once
#include "input_keycodes.h"
#include "keyboard_input.h"
static u8 current_modifier;
#ifdef __cplusplus
extern "C" {
#endif
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;
default: return false;
}
}
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