![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | GameSchool |
Hi
How do I get the name of the currently pressed controller button?
I know I can get the index of it, but I couldn’t find anything about the name.
I noticed that this question was asked before here, but the answer didn’t help.
Thanks
Seems like a niche use case, do you really need to know if ‘A’ is pressed versus ‘fire’ or a shoulder/bumper button?
You could map each to a certain input event with appropriate handlers, thus you know specifically which button was pressed/held/etc due to the handler executing.
spaceyjase | 2023-03-03 17:18
What I meant is that in the UI, I would like to show the name of the button. In the example below you can see that the keyboard button is space and the controller button is 0 (A in Xbox controller).
Instead of 0, I would like to show A in the UI.
I know that I can make a dict that represents the name of the buttons, but a built-in option could be really useful in that case.
GameSchool | 2023-03-03 17:38
Of course. For this, get_joy_name
might give you what you want, with the device index from the input event. A dictionary could be used to look up an icon based on the returned name.
spaceyjase | 2023-03-03 18:18
Browsing YouTube, I also found this that may help: https://m.youtube.com/watch?v=Ox1kMM0qcTk
spaceyjase | 2023-03-04 12:54