Jump to content
Sign in to follow this  
wim1976

Testing for keypress

Recommended Posts

I am writing a weight and balance calculator. I use textboxes to enter values which are used in the calculation. But is it possible to test for the <SHIFT>,<CTRL>,<TAB> etc. keypresses, so that I can uses this to set the focus to a next or previous textbox or widget. Clicking each field with the mouse is somewhat annoying.

Share this post


Link to post
Share on other sites

I'll have to review to be sure. I think you can do it from the global key sniffer but maybe not from a widget directly.

 

Maybe a better solution is to add: gui.setTabOrder( widget_h, index_n ) ?

Share this post


Link to post
Share on other sites

Gizmo has a lot of small little Widget "helper" code in it to make X-Plane less annoying, this is a perfect example of the kind of things I like to do "upstream" so we all get it for free.

Share this post


Link to post
Share on other sites

Thanks for your answer. I have found a solution. With textboxes I can use a the function EventHandler_OnKeyDown(char, keyCode, shift, alt, control), whereby "EventHandler" is replaced by the name which was defined at creating the widget (in my case the textbox).

 

It costed me some time to find this Gizmo function (your answers made me think there must a sort of keysniffer in Gizmo). After searching in my collection of Gizmo scripts (My way of learning programming is always reading code of other who are more clever than I (You understand, I can use everything  :))

 

After all I found one script (Filebrowser.lua) of yours which I downloaded some time ago from Github (I was glad I did, because at the moment it seems you have deleted many gizmo scripts there) where this function was used. After that it was very easy to implement it for my new script.

 

So I think it could be helpful to add this event to the Gizmo64 documentation.

 

Another thing is that I now need a xxx_OnKeyDown() function for every textfield. So defining a taborder at creating the userinterface is a good idea. Another way to have less messy code is to create a function GetFocus() to find the widgetID of the 'active' widget in combination with one xxx_OnKeyDown() function which is used for all widgets of Gizmo. It is an easy way to put all my widgets in a table. I can use the index of the table as the taborder and voila I can tab forward and backwards.

 

Finally a short function using _OnKeyDown() which can be used to write the values to the console, so one gets an understanding how this function can be implemented and which values (of course ASCII values) are generated by your keypresses.

WidgetID   = gui.newTextBox(WindowID,"EventHandler","", 135, 100, 35)function EventHandler_OnKeyDown(char, keyCode, shift, alt, control)    console.log ("char: "..char.." keycode: "..keyCode.." shift: "..tostring(shift).." alt: "..tostring(alt).." control: "..tostring(control))end
Edited by wim1976

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×