Sample for OnKeyUp (+/-) - adjusting a value via keyboard


Recommended Posts

I am looking for a sample code that increases/decreases a value by 1 in a variable (or V-Channel with history) by pressing the +/- - Keys on the keyboard.

I know it has to be done using system events (OnKeyUp,...). I tried but failed up now. Could you help me?

Link to comment
Share on other sites

See attached.

I used OnChar because its easier and will take repeats. I can never remember the key codes, so I put a ? char at the top of the sequence, then just looked at the command / alert window to see what code corresponded to what key as I pressed them. Note also that I made it so both = and +, which are the same key on most keyboards do the same thing. That way you can don't have to hold shift to go up.

Note that this code only has effect when the page is in focus. If you are editing as sequence or in any other view, it won't execute.

Oncharsample.ctl

Link to comment
Share on other sites

It's 5.79a (DF Lite). I marked the StartUp as autostart. Now it is without alert. Thank you.

My mistake was, that I had marked autostart as well in the sequence Onchar.

What do I have to consider implementing this in the following application?:

I use a mechanical encoder (type ALPS) that gives via encoderchip (type Spinwarrior) the key stroke "F14" for +/up and "F15" for -/down. --> that works aktually. The value has to be stored in the registry after shutdown of the device.

Link to comment
Share on other sites

That should work, assuming F14 and F15 generate a standard virtual code. However, you are going to need to use the OnKeyDown event instead of OnChar because OnChar only catches keys that actually result in a character. OnKeyDown will catch virtual keys like the function keys. I believe the variable that gets passed in to OnKeyDown is "key" instead of "char" too.

As for saving to the registry, just use a registry variable: registry.myvar Just remember that these are DWords (signed long integers) and so limited to +/- 2^31

Link to comment
Share on other sites

using your sample worked, but using the same simple thing in my application causes again

"C1000 Channel or function not found: OnChar Line 1 - Uncaught error in sequence OnChar"

So I have no idea

Link to comment
Share on other sites

Please see the file I attached. I use 2 U3-HV in my device. On page "...blau" within the gage (lower left corner), which represents the altitude, the QNH has to be adjusted and stored in the registry.

I have cut out the part with the "registry" because I havent`t understood the basics.

Link to comment
Share on other sites

Archived

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