immersive-home/app/lib/events/event_key.gd

26 lines
901 B
GDScript3
Raw Normal View History

2023-11-22 02:44:07 +02:00
extends EventWithModifiers
2024-03-17 01:14:31 +02:00
## Events emitted by the Virtual Keyboard
2023-11-22 02:44:07 +02:00
class_name EventKey
2024-03-17 01:14:31 +02:00
## The key that was pressed or released
2023-11-22 02:44:07 +02:00
var key: Key
2024-03-17 01:14:31 +02:00
## true if the event is repeated due to a key being held down for a while
2023-11-22 02:44:07 +02:00
var echo: bool
2024-03-17 01:14:31 +02:00
## Modifies a string based on the key pressed
static func key_to_string(key: Key, caps: bool=false, apply_to: String="") -> String:
match key:
KEY_INSERT: apply_to += DisplayServer.clipboard_get()
KEY_BACKSPACE: apply_to = apply_to.substr(0, apply_to.length() - 1)
KEY_SPACE: apply_to += " "
KEY_ASCIITILDE: apply_to += "~"
KEY_SLASH: apply_to += "/"
KEY_BACKSLASH: apply_to += "\\"
2024-01-29 13:37:25 +02:00
KEY_COLON: apply_to += ":"
KEY_COMMA: apply_to += ","
KEY_PERIOD: apply_to += "."
KEY_MINUS: apply_to += "-"
KEY_CAPSLOCK: return apply_to
_: apply_to += OS.get_keycode_string(key).to_upper() if caps else OS.get_keycode_string(key).to_lower()
return apply_to