Page 1 of 1

detecting key presses without adding buttons to a panel

Posted: Thu Jul 11, 2019 4:14 pm
by tpjctrl
Apart from using a button with a defined shotcut key, is there another way to detect a key pressed on a keyboard? I've got a main panel with several buttons and shortcut keys, but whenever a child panel is opened these stop functioning as the focus is on the child panel which doesn't have the same buttons as the main panel.

Regards,
Tom

Re: detecting key presses without adding buttons to a panel

Posted: Fri Jul 12, 2019 2:21 pm
by gschijndel
The function keys can be handled with a 'keypressed.ctl' script.
This is documented under: WinCC OA UI -> Module VISION -> Function keys

Re: detecting key presses without adding buttons to a panel

Posted: Tue Jul 16, 2019 9:07 am
by tpjctrl
Thanks gschijndel! I've found it in the Help file after posting the above question.

Regards,
Tom

Re: detecting key presses without adding buttons to a panel

Posted: Wed Jul 17, 2019 3:45 pm
by tpjctrl
After early celebrations I have to come back with a question. I've noticed that the keypressed.ctl script gets called everytime an F# key is pressed, even when there's currently a function key request being processed. For example, lets say F1 is supposed to turn an indicator on, do a 3sec delay and turn the indicator off and F2 is supposed to put some text on the screen. If F2 is pressed right after F1, then F1 would turn an indicator on, go into delay, then the script would get interrupted with a new request from F2 and some text would get shown on the screen, but the indicator would never turn off as that script got terminated. So in effect all F# keys work on an interrupt basis, but completely ignoring that there might be code still running from the previous F# request.

Is there a way to stop this somehow? Cause with the way it behaves now it's kind of pointless having it in the first place as anyone can press any F# key and stop whatever was processing before. All the usual methods of battling this, like software flags indicating that processing is ongoing don't really mean much, as another F# key press simply re-initialises the script.

Rgds,
Tom

Re: detecting key presses without adding buttons to a panel

Posted: Thu Jul 18, 2019 11:57 am
by adaneau
Hi,

I see potentially 2 solutions :

- Synchronized function inside your keypressed, thus your key listener cannot run twice.
- UI global var as semaphore

Thus you protect the execution of your script. Eventually you could build a queue global mapping, where key pressed add entry and run function and function itself clean mapping entry, combined with synchronized to avoid double execution.

Anyway I guess that with Synchronized and global UI var, it is up to your imagination :)

BR
Alexandre Daneau

Re: detecting key presses without adding buttons to a panel

Posted: Thu Jul 18, 2019 3:38 pm
by tpjctrl
Thanks Alexandre,

I've tried sticking "synchronized" in front of the main function in the keypressed.ctl, but that didn't work or change anything. At this stage I've gone with a dpconnect elsewhere and simply doing a dpSet inside the keypressed, writing the key int value to the DPE. This way the key press is handled outside the keypressed.ctl and it even buffers keypresses due to the nature of dpconnect. Not ideal, but seems to work fine.

Still I'm really surprised it works this way, it wouldn't be a big issue if there was a way to disable the F key interrupt within the keypressed.ctl (like you can on say microcontrollers), but I don't think there is...

Rgds,
Tom