PathPilot Hotkey Problem
- Vmax549
- Offline
- Platinum Member
- Posts: 341
- Thank you received: 28
So on to the problem. I used this code t run the hotkey functions. The F3 alone opens the door fine , Pressing the F3 and the Shift key closes the door BUT then runs the door open again. I have tried every iteration of code I can think of even making it a math equation to no avail. It seems so simple of a function BUT I guess I am missing a fundemental function of the coding.
Does anyone have an idea of how to make this work ???
if event.type == gtk.gdk.KEY_RELEASE:
if kv == gtk.keysyms.F3:
self.error_handler.log("F3 button event")
self.issue_mdi("(debug, Door Opened)")
if event.type == gtk.gdk.KEY_RELEASE:
if kv == gtk.keysyms.F3 | gtk.keysyms.Shift_R:
self.error_handler.log("F3 button event")
self.issue_mdi("(debug, Door Closed)")
( TP
Please Log in or Create an account to join the conversation.
- snowgoer540
- Offline
- Moderator
- Posts: 2394
- Thank you received: 782
Here's one way to solve the problem:
if event.type == gtk.gdk.KEY_RELEASE and not event.state & gtk.gdk.SHIFT_MASK:
if kv == gtk.keysyms.F3 and not self.program_running():
self.error_handler.log("F3 button event")
self.issue_mdi("(debug, Door Opened)")
if event.type == gtk.gdk.KEY_RELEASE and event.state & gtk.gdk.SHIFT_MASK:
if kv == gtk.keysyms.F3 and not self.program_running()
self.error_handler.log("F3 button event")
self.issue_mdi("(debug, Door Closed)")
I had a bit of a google, and I wasn't able to find an easy way to differentiate between left and right shift.
As for how to handle modifier keys in GTK, I had a look at how they handled alt+enter to see how they got there, then googled for the correct shift as a modifier (gtk.gdk.SHIFT_MASK).
Lastly, with your code the reason you always got a response whether you were holding shift or not is because the first if statement simply checks if F3 was the key that was released. It did not take into account if any modifier was being held at the same time or not.
Please Log in or Create an account to join the conversation.
- Vmax549
- Offline
- Platinum Member
- Posts: 341
- Thank you received: 28
Thank You very much for the help. NOW on with the show. Here is a Picture of the addon keypad. It has a total of 26 keys You help me save 6 switch positions. Instead of having to use 2 switchs to open/cose we now only need 1 switch and the shift key from the keyboard.
( TP
Attachments:
Please Log in or Create an account to join the conversation.
- Vmax549
- Offline
- Platinum Member
- Posts: 341
- Thank you received: 28
( TP
Please Log in or Create an account to join the conversation.
- snowgoer540
- Offline
- Moderator
- Posts: 2394
- Thank you received: 782
The different Shift Keys ar Shift_L and Shift_R . I did not realise there was a SHIFT_MASK
Apologies I should have been more clear, I couldn't find a way to differentiate between L and R when they are being used as a modifier key (shift, alt, control PLUS another key).
I also noticed you did a check to make sure the machine was not running. IF you are creating action hotkeys if you route all teh commands through the MDI interface( see the debug,message) then PP does all the error checking to make SURE you are in the machine idle state and it is safe to run.. IF what you are doing cannot be run throught the MDI then you do have to add in the Mode check to ensure it is safe to do the function.
I wondered about the MDI commands. Yea, that's true. You will get a few extra logging events though in those cases. Probably not a bad thing though!
Please Log in or Create an account to join the conversation.
- Vmax549
- Offline
- Platinum Member
- Posts: 341
- Thank you received: 28
( TP
Please Log in or Create an account to join the conversation.