-
Notifications
You must be signed in to change notification settings - Fork 169
/
keyboard.js
41 lines (33 loc) · 1010 Bytes
/
keyboard.js
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
import Clutter from 'gi://Clutter';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
export class Keyboard {
#device;
#contentPurpose;
constructor () {
let seat = Clutter.get_default_backend().get_default_seat();
this.#device = seat.create_virtual_device(Clutter.InputDeviceType.KEYBOARD_DEVICE);
Main.inputMethod.connectObject('notify::content-purpose', (method) => {
this.#contentPurpose = method.content_purpose;
}, this);
}
destroy () {
Main.inputMethod.disconnectObject(this);
this.#device.run_dispose();
}
#notify (key, state) {
this.#device.notify_keyval(
Clutter.get_current_event_time() * 1000,
key,
state
);
}
get purpose () {
return this.#contentPurpose;
}
press (key) {
this.#notify(key, Clutter.KeyState.PRESSED);
}
release (key) {
this.#notify(key, Clutter.KeyState.RELEASED);
}
}