TextField(s)
BlitzMax Forums/MaxGUI Module/TextField(s)
| ||
I'd like to process a "Enter key hit" event in a gadgetfilter of a single line text field. Is it even possible because no events arrive for the enter key? Basically I have linked the text input with bah.muParser to make a simple inline calculator on my forms. eg. the user can type "1234.5678*20" into the text field and upon hitting enter I'd like it to evaluate it. At the moment I'm using a space bar key event which is a bit clumsy. I'm also looking for the method to set the text field cursor position. When the parser evaluates the input I need to move the caret to the end of the line. Thanks in advance. |
| ||
The way is to have an OK Button which catches the enter key ( as a CANCEL Button catches an ESC). This button can be hidden if it disturbs the form. |
| ||
Thanks jsp. I can see the OK button working. I'll just need to figure out which textfield gadget needs parsing. Any hints for setting the caret position? I'll dig into the MaxGUI source if it's not available out of the box. |
| ||
you could use a textarea() gadget. Then you can use the filter feature to react on a KEY=13 input, and after this eliminate it:SuperStrict Import MaxGUI.Drivers Local flags%=WINDOW_DEFAULT|WINDOW_CLIENTCOORDS'|WINDOW_CENTER Global Window:TGadget= CreateWindow("test ENTER key" , 100 , 100 , 800 , 600 , Null , Flags) Global Textfield:TGadget=CreateTextArea(100,100,160,20,window) SetGadgetFilter TextField, Filter, Textfield While WaitEvent() Wend Function filter%(event:TEvent,context:Object) Local Key%=event.data Select event.id Case EVENT_KEYDOWN Print "key down="+ key Select Key Case 48,49,50,51,52,53,54,55,56,57 Return 1 Case 13 Return 0 End Select Case EVENT_KEYCHAR Print "key char="+ key Select Key Case 48,49,50,51,52,53,54,55,56,57 Return 1 Case 13 DoItNow Return 0 End Select End Select Return 0 End Function Function DoItNow() Print "ENTER or RETURN pressed!!!" End Function |
| ||
You can use: Function ActiveGadget:TGadget() Returns The gadget if any that currently has the keyboard focus. and check which gadget had the focus or just read out all textfields you need. Another approach is to use the GadgetLostFocus event the TextField produces when ... losing the focus (also when tabing from one to another gadget). Setting the cursor is not possible via MaxGUI maybe via API. ActivateGadget( TextField ) would select the content and with a single cursor key you are the end of the text but that's all. |
| ||
This is fun :) Midimaster; Your code was exactly my first approach, but no enter key events make it through to the filter function at all. This is because I'm using a single line TextField instead of a TextArea. jsp; I've already plugged into the lost focus event as you suggest and that works fine. Well I've mostly got what I want using a TextArea. Now I just need to kill those silly horizontal scrollbars that appear if the input is too long :/ |
| ||
Something like this: Function ScrollbarOnOff(TextArea:TGadget,Orientation:Int=SB_HORZ,On:Int=False) 'This hides the scrollbar. Change "SB_VERT" To "SB_HORZ" To hide the horizontal scrollbar. 'Change the last parameter To True To show the scrollbar. Local hWnd = QueryGadget(textarea, QUERY_HWND) SendMessageA(hWnd, EM_SHOWSCROLLBAR, Orientation, On) End Function Windows only of course... |