OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / autoloads / key_rules.gd

26 lines · gd ref:
extends RefCounted
## THE LAYOUT RULE (keymap step 5, docs/keymap-blender-279.md §6), on its own so code that
## compiles BEFORE the autoloads exist (operators, --script gates) can use it. Keymap
## delegates here; nothing else should restate it. Users PRELOAD it
## (`const KeyRules := preload("res://autoloads/key_rules.gd")`) — no class_name, so it
## needs no editor import to be found.
##
## A LETTER binding matches the CHARACTER the layout types (Blender: GHOST_SystemX11 takes
## the keysym); anything else matches the key's POSITION (the number row — Blender forces
## it to digits —, numpad, [ ] - =), unless a binding says `by`.


## Does this binding match the key's POSITION (true) or the CHARACTER typed (false)?
static func is_positional(key: int, b: Dictionary = {}) -> bool:
	if b.has("by"):
		return String(b["by"]) == "position"
	return not (key >= KEY_A and key <= KEY_Z)


## The key an event means under the same rule — for code that matches keys itself (the
## operators' axis / step keys): a letter by character, anything else by position.
static func key_of(e: InputEventKey) -> int:
	if e.physical_keycode != 0 and is_positional(int(e.physical_keycode)):
		return int(e.physical_keycode)
	return int(e.keycode) if e.keycode != 0 else int(e.physical_keycode)