Sign in to follow this  
Hubauer

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

So far it worked, but created the following alert:

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

What is the reason?

Share this post


Link to post
Share on other sites

I don't get that error, but I do see that I forgot to mark StartUp as autostart. So you'll have to start it manually to initialize the variable that we are incrementing/decrementing.

What release of DF are you running?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

If its just the ? statement, just delete the line. I'd have to see your .ctl doc otherwise to see what you are doing.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

You can't rename that sequence. It has to be called OnChar. Rename ReadQNHr back to OnChar and it will work.

Nice main screen. I'd love to see a screenshot of it with real data when you are done :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this