Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/client/src/utils/guacamole-keyboard.ts

77 lines
2.3 KiB
TypeScript
Raw Normal View History

2020-06-16 06:45:32 +12:00
import GuacamoleKeyboard from './guacamole-keyboard.js'
export interface GuacamoleKeyboardInterface {
/**
* Fired whenever the user presses a key with the element associated
* with this Guacamole.Keyboard in focus.
2021-03-02 03:10:20 +13:00
*
2020-06-16 06:45:32 +12:00
* @event
* @param {Number} keysym The keysym of the key being pressed.
* @return {Boolean} true if the key event should be allowed through to the
* browser, false otherwise.
*/
2021-03-02 03:10:20 +13:00
onkeydown?: (keysym: number) => boolean
2020-06-16 06:45:32 +12:00
/**
* Fired whenever the user releases a key with the element associated
* with this Guacamole.Keyboard in focus.
2021-03-02 03:10:20 +13:00
*
2020-06-16 06:45:32 +12:00
* @event
* @param {Number} keysym The keysym of the key being released.
*/
2021-03-02 03:10:20 +13:00
onkeyup?: (keysym: number) => void
2020-06-16 06:45:32 +12:00
/**
* Marks a key as pressed, firing the keydown event if registered. Key
* repeat for the pressed key will start after a delay if that key is
* not a modifier. The return value of this function depends on the
* return value of the keydown event handler, if any.
2021-03-02 03:10:20 +13:00
*
2020-06-16 06:45:32 +12:00
* @param {Number} keysym The keysym of the key to press.
* @return {Boolean} true if event should NOT be canceled, false otherwise.
*/
2021-03-02 03:10:20 +13:00
press: (keysym: number) => boolean
2020-06-16 06:45:32 +12:00
/**
* Marks a key as released, firing the keyup event if registered.
2021-03-02 03:10:20 +13:00
*
2020-06-16 06:45:32 +12:00
* @param {Number} keysym The keysym of the key to release.
*/
2021-03-02 03:10:20 +13:00
release: (keysym: number) => void
2020-06-16 06:45:32 +12:00
/**
* Presses and releases the keys necessary to type the given string of
* text.
*
* @param {String} str
* The string to type.
*/
2021-03-02 03:10:20 +13:00
type: (str: string) => void
2020-06-16 06:45:32 +12:00
/**
* Resets the state of this keyboard, releasing all keys, and firing keyup
* events for each released key.
*/
2021-03-02 03:10:20 +13:00
reset: () => void
2020-06-16 06:45:32 +12:00
/**
* Attaches event listeners to the given Element, automatically translating
* received key, input, and composition events into simple keydown/keyup
* events signalled through this Guacamole.Keyboard's onkeydown and
* onkeyup handlers.
*
* @param {Element|Document} element
* The Element to attach event listeners to for the sake of handling
* key or input events.
*/
2021-03-02 03:10:20 +13:00
listenTo: (element: Element | Document) => void
2020-06-16 06:45:32 +12:00
}
2021-03-02 03:10:20 +13:00
export default function (element?: Element): GuacamoleKeyboardInterface {
2021-03-29 08:44:43 +13:00
const Keyboard = {}
2020-06-16 06:45:32 +12:00
2021-03-02 03:10:20 +13:00
GuacamoleKeyboard.bind(Keyboard, element)()
2020-06-16 06:45:32 +12:00
2021-03-02 03:10:20 +13:00
return Keyboard as GuacamoleKeyboardInterface
2020-06-16 06:45:32 +12:00
}