Skip to content

Commit

Permalink
fix: input mapping for special keys (enter, tab, ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
myin142 committed May 21, 2023
1 parent 407ba88 commit 1430f07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions addons/input-system/InputType.gd
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,23 @@ static func to_text(type: int) -> String:

var ev = to_event(type) as InputEventKey
if ev:
return String.chr(ev.unicode)
if ev.unicode:
var char = String.chr(ev.unicode)
if char == " ":
return "Space"
return char
return ev.as_text()
return ""


static func to_event(type: int) -> InputEvent:
if type <= 0:
var key = InputEventKey.new()
key.unicode = -type
var code = -type
if code >= KEY_SPECIAL:
key.keycode = code
else:
key.unicode = code
return key

if type >= Key.JOYSTICK_L_UP and type <= Key.JOYSTICK_R_LEFT:
Expand Down Expand Up @@ -120,7 +129,10 @@ static func to_event(type: int) -> InputEvent:

static func to_type(event: InputEvent) -> int:
if event is InputEventKey:
return -event.unicode
if event.unicode: # ASCII should only return unicodes ?
return -event.unicode

return -event.keycode # Special Keys like Enter, Tab should only have keycode ?

if event is InputEventJoypadMotion and event.axis_value != 0:
for key in JOY_MOTION_MAP:
Expand Down
4 changes: 3 additions & 1 deletion src/menu/Options.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_sb63w")

[node name="CenterContainer" type="CenterContainer" parent="."]
Expand Down Expand Up @@ -61,7 +63,7 @@ grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_qgskr")
script = ExtResource("3_pt256")
actions = Array[String](["move_up", "move_left", "move_right", "move_down"])
actions = Array[String](["move_up", "move_left", "move_right", "move_down", "fire", "cast", "interact"])
container = NodePath("../CenterContainer/VBoxContainer/Options")
popup = NodePath(".")
remap_btn = ExtResource("5_34cxq")
Expand Down

0 comments on commit 1430f07

Please sign in to comment.