add kle numpad recognition
This commit is contained in:
parent
702c83afb2
commit
b41ee1d85d
@ -25,15 +25,20 @@ const LABEL_TO_KEYCODE_MAP: Dictionary[String, Key] = {
|
||||
"PgDn": KEY_PAGEDOWN,
|
||||
"Page Down": KEY_PAGEDOWN,
|
||||
"Num Lock": KEY_NUMLOCK,
|
||||
"*": KEY_KP_MULTIPLY,
|
||||
"+": KEY_KP_ADD,
|
||||
"Del": KEY_KP_PERIOD,
|
||||
"↑": KEY_UP,
|
||||
"←": KEY_LEFT,
|
||||
"↓": KEY_DOWN,
|
||||
"→": KEY_RIGHT,
|
||||
}
|
||||
|
||||
const LABEL_TO_NUMPAD_KEYCODE_MAP: Dictionary[String, Key] = {
|
||||
"/": KEY_KP_DIVIDE,
|
||||
"*": KEY_KP_MULTIPLY,
|
||||
"-": KEY_KP_SUBTRACT,
|
||||
"+": KEY_KP_ADD,
|
||||
".": KEY_KP_PERIOD,
|
||||
}
|
||||
|
||||
const W := "w"
|
||||
const H := "h"
|
||||
const X := "x"
|
||||
@ -123,7 +128,9 @@ func _deserialize_row(data_row: Array) -> Array[Dictionary]:
|
||||
if key_data is String:
|
||||
var key_dict := {
|
||||
KeyProps.KEY:
|
||||
_get_keycode_from_legend(key_data as String, current_key_data_dict)
|
||||
_get_keycode_from_legend(
|
||||
(key_data as String).split("\n"), current_key_data_dict
|
||||
)
|
||||
}
|
||||
key_dict.merge(_deserialize_key(current_key_data_dict))
|
||||
layout_row.append(key_dict)
|
||||
@ -168,28 +175,48 @@ func _cleanup_key_data_dict(data_key: Dictionary) -> Dictionary:
|
||||
return data_key
|
||||
|
||||
|
||||
func _get_keycode_from_legend(legend: String, data_key: Dictionary) -> Key:
|
||||
if legend == "" and data_key.has(W) and data_key[W] > 1:
|
||||
func _get_keycode_from_legend(legend: Array[String], data_key: Dictionary) -> Key:
|
||||
if legend.size() == 1 and legend[0] == "" and data_key.has(W) and data_key[W] > 1:
|
||||
return KEY_SPACE
|
||||
|
||||
var labels := legend.split("\n")
|
||||
var keycode := KEY_NONE
|
||||
|
||||
var keycode := OS.find_keycode_from_string(labels[0])
|
||||
keycode = _get_numpad_keycode_from_legend(legend)
|
||||
|
||||
if keycode == KEY_NONE and labels.size() == 2:
|
||||
keycode = OS.find_keycode_from_string(labels[1])
|
||||
if keycode == KEY_NONE:
|
||||
keycode = OS.find_keycode_from_string(legend[0])
|
||||
|
||||
if keycode == KEY_NONE and legend.size() == 2:
|
||||
keycode = OS.find_keycode_from_string(legend[1])
|
||||
|
||||
if keycode == KEY_NONE and legend.size() == 2:
|
||||
if LABEL_TO_KEYCODE_MAP.has(legend[1]):
|
||||
keycode = LABEL_TO_KEYCODE_MAP[legend[1]]
|
||||
elif LABEL_TO_KEYCODE_MAP.has(legend[0]):
|
||||
keycode = LABEL_TO_KEYCODE_MAP[legend[0]]
|
||||
|
||||
if (
|
||||
keycode == KEY_NONE
|
||||
and LABEL_TO_KEYCODE_MAP.has(labels[1] if labels.size() == 2 else labels[0])
|
||||
and legend.size() == 1
|
||||
and LABEL_TO_KEYCODE_MAP.has(legend[0])
|
||||
):
|
||||
keycode = LABEL_TO_KEYCODE_MAP[labels[1] if labels.size() == 2 else labels[0]]
|
||||
|
||||
if keycode == KEY_NONE and labels.size() == 2:
|
||||
keycode = LABEL_TO_KEYCODE_MAP[labels[0]]
|
||||
keycode = LABEL_TO_KEYCODE_MAP[legend[0]]
|
||||
|
||||
if keycode == KEY_NONE:
|
||||
printerr("could not recognize key label %s" % labels)
|
||||
printerr("%s: could not recognize key label %s" % [_name, str(legend)])
|
||||
return KEY_UNKNOWN
|
||||
|
||||
return keycode
|
||||
|
||||
|
||||
func _get_numpad_keycode_from_legend(legend: Array[String]) -> Key:
|
||||
if legend.size() == 1 or legend.size() == 2:
|
||||
if legend[0].length() == 1 and legend[0].is_valid_int():
|
||||
return KEY_KP_0 + int(legend[0]) as Key
|
||||
if (
|
||||
LABEL_TO_NUMPAD_KEYCODE_MAP.has(legend[0])
|
||||
and not (legend.size() == 2 and legend[1].length() == 1)
|
||||
):
|
||||
return LABEL_TO_NUMPAD_KEYCODE_MAP[legend[0]]
|
||||
|
||||
return KEY_NONE
|
||||
|
||||
Loading…
Reference in New Issue
Block a user