PathPilot Hotkey Problem

More
25 Apr 2023 22:18 #269909 by Vmax549
Hi Guys I am working on hotkey and in order to save available key on the keypad I have created hotkey that can use a modifier key. I use these where I have a function that turns ON and turns OFF a function such as open door / close door. In this case I used F3 to open the door and Shift_F3 to close the door. The primary key (F3) comes from the keypad and the modifier key(shift) comes from the keyboard. That part works fine, no problems. 

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.

More
25 Apr 2023 23:49 - 26 Apr 2023 00:22 #269925 by snowgoer540
Evening, 

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.
Last edit: 26 Apr 2023 00:22 by snowgoer540.
The following user(s) said Thank You: tommylight, Clive S

Please Log in or Create an account to join the conversation.

More
26 Apr 2023 02:59 - 26 Apr 2023 03:02 #269940 by Vmax549
Replied by Vmax549 on topic PathPilot Hotkey Problem
  AH ok, I look for the shift in the wrong place. The different Shift Keys ar Shift_L and Shift_R . I did not realise there was a SHIFT_MASK

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:
Last edit: 26 Apr 2023 03:02 by Vmax549.

Please Log in or Create an account to join the conversation.

More
26 Apr 2023 03:15 #269942 by Vmax549
Replied by Vmax549 on topic PathPilot Hotkey Problem
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.

(;-) TP

Please Log in or Create an account to join the conversation.

More
26 Apr 2023 11:37 #269970 by snowgoer540

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.

More
26 Apr 2023 20:37 #270002 by Vmax549
Replied by Vmax549 on topic PathPilot Hotkey Problem
I learn long ago working with PP that the logfile is your best friend IF you actually use it.

(;-) TP
The following user(s) said Thank You: tommylight, snowgoer540

Please Log in or Create an account to join the conversation.

Moderators: cncbasher
Time to create page: 0.164 seconds
Powered by Kunena Forum