xref: /openbmc/qemu/include/ui/kbd-state.h (revision 09a274d8)
1 /*
2  * This work is licensed under the terms of the GNU GPL, version 2 or
3  * (at your option) any later version.  See the COPYING file in the
4  * top-level directory.
5  */
6 #ifndef QEMU_UI_KBD_STATE_H
7 #define QEMU_UI_KBD_STATE_H 1
8 
9 #include "qapi/qapi-types-ui.h"
10 
11 typedef enum QKbdModifier QKbdModifier;
12 
13 enum QKbdModifier {
14     QKBD_MOD_NONE = 0,
15 
16     QKBD_MOD_SHIFT,
17     QKBD_MOD_CTRL,
18     QKBD_MOD_ALT,
19     QKBD_MOD_ALTGR,
20 
21     QKBD_MOD_NUMLOCK,
22     QKBD_MOD_CAPSLOCK,
23 
24     QKBD_MOD__MAX
25 };
26 
27 typedef struct QKbdState QKbdState;
28 
29 /**
30  * qkbd_state_init: init keyboard state tracker.
31  *
32  * Allocates and initializes keyboard state struct.
33  *
34  * @con: QemuConsole for this state tracker.  Gets passed down to
35  * qemu_input_*() functions when sending key events to the guest.
36  */
37 QKbdState *qkbd_state_init(QemuConsole *con);
38 
39 /**
40  * qkbd_state_free: free keyboard tracker state.
41  *
42  * @kbd: state tracker state.
43  */
44 void qkbd_state_free(QKbdState *kbd);
45 
46 /**
47  * qkbd_state_key_event: process key event.
48  *
49  * Update keyboard state, send event to the guest.
50  *
51  * This function takes care to not send suspious events (keyup event
52  * for a key not pressed for example).
53  *
54  * @kbd: state tracker state.
55  * @qcode: the key pressed or released.
56  * @down: true for key down events, false otherwise.
57  */
58 void qkbd_state_key_event(QKbdState *kbd, QKeyCode qcode, bool down);
59 
60 /**
61  * qkbd_state_set_delay: set key press delay.
62  *
63  * When set the specified delay will be added after each key event,
64  * using qemu_input_event_send_key_delay().
65  *
66  * @kbd: state tracker state.
67  * @delay_ms: the delay in miliseconds.
68  */
69 void qkbd_state_set_delay(QKbdState *kbd, int delay_ms);
70 
71 /**
72  * qkbd_state_key_get: get key state.
73  *
74  * Returns true when the key is down.
75  *
76  * @kbd: state tracker state.
77  * @qcode: the key to query.
78  */
79 bool qkbd_state_key_get(QKbdState *kbd, QKeyCode qcode);
80 
81 /**
82  * qkbd_state_modifier_get: get modifier state.
83  *
84  * Returns true when the modifier is active.
85  *
86  * @kbd: state tracker state.
87  * @mod: the modifier to query.
88  */
89 bool qkbd_state_modifier_get(QKbdState *kbd, QKbdModifier mod);
90 
91 /**
92  * qkbd_state_lift_all_keys: lift all pressed keys.
93  *
94  * This sends key up events to the guest for all keys which are in
95  * down state.
96  *
97  * @kbd: state tracker state.
98  */
99 void qkbd_state_lift_all_keys(QKbdState *kbd);
100 
101 #endif /* QEMU_UI_KBD_STATE_H */
102