Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
m1k1o
GitHub Repository: m1k1o/neko
Path: blob/master/client/src/utils/guacamole-keyboard.ts
1301 views
1
import GuacamoleKeyboard from './guacamole-keyboard.js'
2
3
export interface GuacamoleKeyboardInterface {
4
/**
5
* Fired whenever the user presses a key with the element associated
6
* with this Guacamole.Keyboard in focus.
7
*
8
* @event
9
* @param {Number} keysym The keysym of the key being pressed.
10
* @return {Boolean} true if the key event should be allowed through to the
11
* browser, false otherwise.
12
*/
13
onkeydown?: (keysym: number) => boolean
14
15
/**
16
* Fired whenever the user releases a key with the element associated
17
* with this Guacamole.Keyboard in focus.
18
*
19
* @event
20
* @param {Number} keysym The keysym of the key being released.
21
*/
22
onkeyup?: (keysym: number) => void
23
24
/**
25
* Marks a key as pressed, firing the keydown event if registered. Key
26
* repeat for the pressed key will start after a delay if that key is
27
* not a modifier. The return value of this function depends on the
28
* return value of the keydown event handler, if any.
29
*
30
* @param {Number} keysym The keysym of the key to press.
31
* @return {Boolean} true if event should NOT be canceled, false otherwise.
32
*/
33
press: (keysym: number) => boolean
34
35
/**
36
* Marks a key as released, firing the keyup event if registered.
37
*
38
* @param {Number} keysym The keysym of the key to release.
39
*/
40
release: (keysym: number) => void
41
42
/**
43
* Presses and releases the keys necessary to type the given string of
44
* text.
45
*
46
* @param {String} str
47
* The string to type.
48
*/
49
type: (str: string) => void
50
51
/**
52
* Resets the state of this keyboard, releasing all keys, and firing keyup
53
* events for each released key.
54
*/
55
reset: () => void
56
57
/**
58
* Attaches event listeners to the given Element, automatically translating
59
* received key, input, and composition events into simple keydown/keyup
60
* events signalled through this Guacamole.Keyboard's onkeydown and
61
* onkeyup handlers.
62
*
63
* @param {Element|Document} element
64
* The Element to attach event listeners to for the sake of handling
65
* key or input events.
66
*/
67
listenTo: (element: Element | Document) => void
68
}
69
70
export default function (element?: Element): GuacamoleKeyboardInterface {
71
const Keyboard = {}
72
73
GuacamoleKeyboard.bind(Keyboard, element)()
74
75
return Keyboard as GuacamoleKeyboardInterface
76
}
77
78