godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.14k stars 21.19k forks source link

Scancode always 0 for physical keys #65998

Closed stephanbogner closed 2 years ago

stephanbogner commented 2 years ago

Godot version

v3.4.4.stable.official

System information

macOS Monterey 12.1

Issue description

I am not sure if this is the intended behaviour when working with physical keys, because I didn't find any information in the docs about this.

Description:

Expectation:

Context

Steps to reproduce

Input map

Screenshot 2022-09-17 at 19 21 28

Code

func _ready():
    print('Physical:')
    var scancode_physical = InputMap.get_action_list("debug_button")[0].scancode
    var keyname_physical = OS.get_scancode_string(scancode_physical)
    print('Scancode: ', scancode_physical, ' = ', keyname_physical)

    print('')

    print('Not physical:')
    var scancode = InputMap.get_action_list("debug_button")[1].scancode
    var keyname = OS.get_scancode_string(scancode)
    print('Scancode: ', scancode, ' = ', keyname)

Output

Physical:
Scancode: 0 = 

Not physical:
Scancode: 32 = Space

Minimal reproduction project

No response

KoBeWi commented 2 years ago

Physical events use physical_scancode instead.

stephanbogner commented 2 years ago

@KoBeWi Wow that reply was fast! Thanks for the clarification! ❤️ (As this solves my question I am closing the issue)

I also discovered issue 3571 now which helped me understand a bit more.

I don't really understand why there are separate ways to get the scancode, as the physical_scancode for non-physical keys is 0 (so it seems streamlining to scancode could make sense) ... but I am still learning so there probably is a good reason 🙂

Code

func _ready():
    print('Physical:')
    var action_physical = InputMap.get_action_list("debug_button")[0]
    print('scancode_physical: ', action_physical.physical_scancode )
    print('scancode: ', action_physical.scancode )
    print('')
    print('Not physical:')
    var action = InputMap.get_action_list("debug_button")[1]
    print('scancode_physical: ', action.physical_scancode )
    print('scancode: ', action.scancode )

Output

Physical:
scancode_physical: 32
scancode: 0

Not physical:
scancode_physical: 0
scancode: 32
lolouthefox commented 8 months ago

Where did get_action_list go? It doesn't work anymore, anything changed?