Hubauer Posted March 1, 2009 Share Posted March 1, 2009 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 More sharing options...
AzeoTech Posted March 2, 2009 Share Posted March 2, 2009 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 More sharing options...
Hubauer Posted March 8, 2009 Author Share Posted March 8, 2009 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? Link to comment Share on other sites More sharing options...
AzeoTech Posted March 8, 2009 Share Posted March 8, 2009 I don't know. What does line 1 say? Link to comment Share on other sites More sharing options...
Hubauer Posted March 8, 2009 Author Share Posted March 8, 2009 Line 1: ? Char Link to comment Share on other sites More sharing options...
AzeoTech Posted March 8, 2009 Share Posted March 8, 2009 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? Link to comment Share on other sites More sharing options...
Hubauer Posted March 8, 2009 Author Share Posted March 8, 2009 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 More sharing options...
AzeoTech Posted March 9, 2009 Share Posted March 9, 2009 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 More sharing options...
Hubauer Posted March 9, 2009 Author Share Posted March 9, 2009 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 More sharing options...
AzeoTech Posted March 9, 2009 Share Posted March 9, 2009 If its just the ? statement, just delete the line. I'd have to see your .ctl doc otherwise to see what you are doing. Link to comment Share on other sites More sharing options...
Hubauer Posted March 9, 2009 Author Share Posted March 9, 2009 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 More sharing options...
AzeoTech Posted March 9, 2009 Share Posted March 9, 2009 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.