Mapping Key-Stroke Press To Button Press


Recommended Posts

In my file I have an eStop button component which, when pressed, begins a quick-sequence.

Is there any way to map a key-stroke to that button? What I would like to be able to do is for the user to press a key, let's say the Esc key, and that would be equivalent to pressing the eStop button in my file.

Link to comment
Share on other sites

OK, first, automation 101 (and you may know this, but since lots of people read these posts):

DO NOT run an emergency stop button through any sort of logic. This means a PC or a PLC. E-Stop buttons should be hard wired in a way that shuts down the system as rapidly as possible, even if that loses product or possibly even damages machinery, to protect the user. Typically power to machinery is sent directly through the E-Stop, or via an FM-certified relay so that when the E-Stop distrupts the power, everything shuts down properly. The proper design of an e-stop is outside the scope of this forum and varies depending on the application, but the one golden rule I'll repeat: do not run it through the PC or PLC. This is not a DAQFactory thing. Remember also that a PLC is just a computer that runs one task. PLCs fail, and so e-stops shouldn't go through them either.

So, let's instead call your button "System stop" instead of E-Stop or Emergency Stop. I'll assume you have some sort of hardware E-Stop to protect your users.

Next, be warned, albeit less sternly: using single keystrokes to activate actions can cause problems. It depends a little on how the keyboard is mounted, but if its sitting on a table, for example, what happens if someone comes along and loses their balance and puts their hand down on the keyboard to steady themselves? Or they drop some papers on the desk and some of them land on some keys? We've all certainly done that on our desk computers. So, be aware of that when you are physically arranging the system.

Now the answer to your question: you want to use a system event (see 5.28 in user's guide), specifically OnChar(): This event triggers whenever you press a key. You can also use onkeyup or onkeydown, the concept is the same. Those are more useful for doing repetitive actions (i.e. do something as long as the key is pressed), or for handling special keys that OnChar doesn't get triggered by (i.e. the function F1-F12 keys). To create a system event handler, simply create a sequence called "OnChar". The key code is passed into this function as the "Char" private variable. You can then look for a particular code and trigger a sequence from it. Make sure and start the sequence with beginSeq() unless its really fast since OnChar and the other system events run in the UI thread. Not doing this will cause your application to be sluggish or even hang.

I personally can never remember what the key codes are, so I start by creating a simple OnChar sequence and putting:

? char

as the only line. Then I go to a page and press the keys I want. The key code will for the desired key will display in the command / alert window. If it doesn't, then you have a special key and probably need onkeydown or Up. Then I can go back and edit the OnChar sequence to look for that particular code using a simple if. For Esc, its 27, so your script might end up like this:


if (char == 27)
beginSeq(systemStop)
endif

[/CODE]

There are additional parameters passed in to tell you if Shift or Ctrl is pressed.

Link to comment
Share on other sites

  • 1 year later...

Found the problem. It doesn't report back all key press combinations (for example Ctrl + any number key). So I thought I had to begin the sequence and that generated the error.

 

Doesn't seem to return anything with the Alt key pressed and nothing for function keys. How can a function key press be detected and an Alt function key press?

Link to comment
Share on other sites

If you want to manage key strokes, is it all done in the one sequence no matter where you are in your project? No way to do in a context sensitive manner?

 

Looks like if you want to be able to tab between input fields that functionality has to be coded, and if you have a lot of different input forms coding that alone could result in a pretty big sequence. Any way to program generically tabbing between fields.

Link to comment
Share on other sites

OnChar has two separate parameters to tell you if Shift and Ctrl are pressed.  See 5.28.  You can't detect Alt, because the OS uses it for the menus and the like.  Function keys aren't considered chars by windows so you have to use OnKeyDown/Up.  This is actually a windows thing, not DAQFactory.  We are largely just passing the windows events to DAQFactory script.

 

As for tabbing between fields, this is a request we are working on to simplify.

Link to comment
Share on other sites

Somewhere else you had an example of tabbing between user name and password input fields. I'm having two problems converting that example to work for my project. One is every time I use that technique to tab between fields Windows generates a sound. That could get pretty annoying. Is there any way to use the tab key to change fields without the sound?

 

Second problem is a big one. Using OnKeyUp/Down does not work with the tab key in a popup window. They report nothing when the tab key is pressed. So far my efforts to use a popup window to gather user entered data is disappointing. Window pops up, have to click in first data entry field before any data can be entered. Then have to take your hand off the keyboard to use the mouse to click on the next data entry and so on for each data entry field. Not user friendly at all. Is there some way to make this work better?

 

Was hoping to build several different popup windows to collect user entered data. One popup would collect contact information from users like names, telephone numbers, and emails for contacting in case of alarms. Another popup window would be used to enter information about variables as an alternative to using channels for data collection and process control. Had plans for a whole series of popups for user input to the process, How can we make these work in a more user friendly manner? Is there a better alternative?

Link to comment
Share on other sites

As for the sound, that is Windows and I've never heard of that happening before.

 

As for the popup, we will look into making tabbing work correctly without scripting.  I don't know how long that will take.  In the meantime, keep this in mind: most end user's use a mouse.  As a developer its hard to imagine, and I'm always trying to show people how much easier it is to use tab, Alt-tab and various other shortcuts, and yet most everyone I work with still likes to use the mouse.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.