Python Forum
run different functions each time the same button is pressed?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
run different functions each time the same button is pressed?
#1
I am using python inputs library to detect gamepad button presses.

Purpose: I want to change the listening mode of my Pioneer AV-Receiver when pressing RB on my Xbox Controller. The event is logged as 'BTN_TR' through python inputs library.

Right now when I press the button it loops through all added listening modes when I press RB once. (as expected) but that's not what I want. I want to change from one listening mode to the next each time I press RB.

So when I press RB for the first time it should switch from Auto Surround to Rock/Pop. When I press RB again it should switch to Ext.Stereo. And the third time I press RB it should switch back to Auto Surround.

This is my code right now. What do I need to change?

def main():
	while 1:
		events = get_gamepad()
		for event in events:

			lmd_query = eiscp.eISCP('192.168.0.59').raw('LMDQSTN')

			if lmd_query == 'LMD80': #autosurround 
				if event.code == 'BTN_TR':  
					eiscp.eISCP('192.168.0.59').raw('LMD06') #rockpop  
   
			if lmd_query == 'LMD06':  
				if event.code == 'BTN_TR':
					eiscp.eISCP('192.168.0.59').raw('LMD0C') #ext.stereo

			if lmd_query == 'LMD0C':  
				if event.code == 'BTN_TR':
					eiscp.eISCP('192.168.0.59').raw('LMD80')
				
if __name__ == "__main__":
	main()
Thank you for reading and if you have an idea please let me know!
Reply


Messages In This Thread
run different functions each time the same button is pressed? - by User3000 - Jul-31-2020, 09:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting button pressed number Moris526 4 2,492 Dec-14-2020, 01:41 AM
Last Post: Moris526
  How many times was the button pressed in pyglet rama27 0 1,947 Oct-10-2020, 10:26 AM
Last Post: rama27
  Terminate a process when hotkey is pressed 66Gramms 0 2,275 Dec-24-2019, 06:41 PM
Last Post: 66Gramms
  Advance program when certain keys are pressed? Chrislw324 2 2,374 May-19-2019, 07:13 PM
Last Post: woooee
  Count to movement according to the time pressed button noartist 1 2,557 Feb-27-2019, 01:33 PM
Last Post: noartist
  Time multiple functions within functions Cortessizzz 4 3,173 Jan-09-2019, 04:15 PM
Last Post: Cortessizzz
  How can classes access each other Functions and Variables at the same time PythonOK 4 3,103 Dec-09-2018, 03:46 AM
Last Post: ichabod801
  What key pressed? ian 2 5,033 Jul-29-2018, 02:30 AM
Last Post: snippsat
  Can't edit code after I've pressed enter. xBlackHeartx 2 12,167 Sep-02-2017, 10:04 PM
Last Post: nilamo
  Button Presses in Certain Time Frame MsCheeseyPuff 3 4,063 Jun-30-2017, 08:39 PM
Last Post: MsCheeseyPuff

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020