detect button press and use it in a Python script?
#1
hi guys, I need help. How do I detect a button press (of my Xbox Controller) in Python?

I need to use it as part of an if-condition. Basically this:

"if button b is pressed then ..."

Any ideas?
Thanks guys!
Reply
#2
you could map a key to run a script
https://kodi.wiki/view/Keymap#Add-on_built-in.27s
Reply
#3
I have already mapped my buttons. In this case it' not an option though.

I actually need the Python code which detects a button press. 

Like I described above I need it as an if-condition.

What does the Python code look like for: "if button b is pressed"?
Reply
#4
You could create a service addon that listens to all the incoming notifications and does something if the notification is about a key press (and specifically the correct key press).

Here's a little bit about service addons:

https://kodi.wiki/view/Service_add-ons

And specifically the onNotification hook:

https://codedocs.xyz/xbmc/xbmc/group__py...7a8a9a8dc7

I don't remember off hand what notification event you need to listen for, so you might need to just create the service addon and have it log the messages to see if you can figure out which one will correspond to a keypress.

One last option. I've never used it, but there is an addon called Kodi Callbacks that might let you configure an event using a keypress as a trigger.

https://kodi.wiki/view/Add-on:Kodi_Callbacks
Reply
#5
thank you! I need more help though. I tried the Kodi Callback add-on. (I knew it before and used it for other stuff.) It's not of any use for regarding pressing buttons.

I am still pretty much clueless what to do.
Reply
#6
perhaps you can use the python inputs library: https://inputs.readthedocs.io/en/latest/index.html
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#7
Thank you @ronie and @pkscout 

I created a service add-on and used python inputs library. Finally it's working.

Appreciate your help!!
Reply



Logout Mark Read Team Forum Stats Members Help
detect button press and use it in a Python script?0
This forum uses Lukasz Tkacz MyBB addons.