Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scancode always 0 for physical keys #65998

Closed
stephanbogner opened this issue Sep 17, 2022 · 3 comments
Closed

Scancode always 0 for physical keys #65998

stephanbogner opened this issue Sep 17, 2022 · 3 comments
Labels

Comments

@stephanbogner
Copy link

stephanbogner commented Sep 17, 2022

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:

  • (See example code below for easier understanding)
  • When I try to access the scancode of a physical button (defined in the Input Map) it always returns 0.
  • If I retrieve the scan code for a "normal" key it works as intended (e.g. 32 for the space-bar)

Expectation:

  • My assumption would have been that the scancode equals whatever the current hardware's keys represent.
  • Example (as explained in the blog post) WASD equals ZQSD on a French keyboard:
    • That would mean that the scancode for physical W-key (scancode 87) would refer to the Z-key on a French keyboard and thus return the scancode 90

Context

  • I am trying to make a smooth way to handle different control schemes (a user should be able to switch between control schemes or even create a custom one). I was trying to abstract it to support local multiplayer nicely.
  • Main code idea: Compare the scancode of an input key with the scancode of the (physical) keys defined in the Input Map.

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
Copy link
Member

KoBeWi commented Sep 17, 2022

Physical events use physical_scancode instead.

@stephanbogner
Copy link
Author

stephanbogner commented Sep 17, 2022

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants