detecting key presses without adding buttons to a panel

Discussion about recent product features & solutions!
Search

Post Reply
6 posts • Page 1 of 1
tpjctrl
Posts: 43
Joined: Tue May 08, 2018 8:30 am

detecting key presses without adding buttons to a panel

Post by tpjctrl » Thu Jul 11, 2019 4:14 pm

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

gschijndel
Posts: 91
Joined: Tue Jan 15, 2019 2:12 pm

Re: detecting key presses without adding buttons to a panel

Post by gschijndel » Fri Jul 12, 2019 2:21 pm

The function keys can be handled with a 'keypressed.ctl' script.
This is documented under: WinCC OA UI -> Module VISION -> Function keys

tpjctrl
Posts: 43
Joined: Tue May 08, 2018 8:30 am

Re: detecting key presses without adding buttons to a panel

Post by tpjctrl » Tue Jul 16, 2019 9:07 am

Thanks gschijndel! I've found it in the Help file after posting the above question.

Regards,
Tom

tpjctrl
Posts: 43
Joined: Tue May 08, 2018 8:30 am

Re: detecting key presses without adding buttons to a panel

Post by tpjctrl » Wed Jul 17, 2019 3:45 pm

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

User avatar
adaneau
Posts: 183
Joined: Tue Feb 21, 2012 8:49 am

Re: detecting key presses without adding buttons to a panel

Post by adaneau » Thu Jul 18, 2019 11:57 am

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

tpjctrl
Posts: 43
Joined: Tue May 08, 2018 8:30 am

Re: detecting key presses without adding buttons to a panel

Post by tpjctrl » Thu Jul 18, 2019 3:38 pm

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

Post Reply
6 posts • Page 1 of 1