curly
Full Member
Posts: 161
|
Post by curly on May 7, 2021 12:23:06 GMT -5
Hi again,
I have one textbox for variable length text, and a button to move on when all required text has been typed into textbox.
Problem I have is that when a line of text is typed, it is much easier to hit the return key rather than find the mouse and click the button.
I've tried using timer to loop through putting focus on the textbox, reading the contents, and then putting focus on the button, but it doesn't want to play with me?
insert code here
print #home.st3, "!show" print #home.tb3, "!show" print #home.b2, "!show"
timer 300, [GettingUserName] [GettingUserName] #home.tb3, "!setfocus" #home.tb3, "!contents? temp$" #home.b1, "!setfocus" wait
|
|
|
Post by mknarr on May 7, 2021 13:24:36 GMT -5
This might help:
'Enter key demo nomainwin WindowWidth = 355 WindowHeight = 220 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) TextboxColor$ = "white" statictext #main.st1,"",100,120,150,25 textbox #main.tb1, 100, 20, 100, 25 textbox #main.tb2, 100, 50, 100, 25 textbox #main.tb3, 100, 80, 100, 25 open "Enter Key Demo" for dialog_modal as #main #main, "font arial 10" #main, "trapclose [quit]" hTextbox1=hwnd(#main.tb1)'get handles of textboxes hTextbox2=hwnd(#main.tb2) hTextbox3=hwnd(#main.tb3) #main.tb1,"!setfocus" timer 50, [enterkey]'goto [editkey] every 50 milliseconds to check for Enter key press wait [enterkey] CallDLL #user32, "GetAsyncKeyState",_VK_RETURN as long,fKeyPress as long if fKeyPress <0 then 'if Enter or Return key is pressed 'set focus to next text box based on what text box currently has focus calldll #user32,"GetFocus",textboxHandle as long select case textboxHandle case hTextbox1 #main.tb2,"!setfocus" 'set focus to next text box 'Do something with the text from textbox1 case hTextbox2 #main.tb3,"!setfocus" 'Do something with the text from textbox 2 case hTextbox3 'replace this section with the action that completes 'the operation the window is meant to perform #main.st1,"Action complete" #main.tb1,"!setfocus" end select end if wait
[quit] close #main end
Using the Enter key to move between text boxes and complete an action.
And here is one from Janet
Nomainwin WindowWidth = 600 WindowHeight = 400 UpperLeftX = Int((DisplayWidth - WindowWidth) /2) UpperLeftY = Int((DisplayHeight - WindowHeight) /2) Statictext #demo.txt1, "First Name", 20, 62, 120, 30 Statictext #demo.txt2, "Middle Initial", 20, 92, 120, 30 Statictext #demo.txt3, "Last name", 20, 122, 120, 30 Textbox #demo.tb1, 150, 60, 200, 30 Textbox #demo.tb2, 150, 90, 200, 30 Textbox #demo.tb3, 150, 120, 200, 30 ' Code for creating a default button in a regular window ' from LBPE Stylebits Series Stylebits #demo.btn0, _BS_DEFPUSHBUTTON, 0, 0, 0 Button #demo.btn0, "", BtnCycle, UL, -100, -100 Button #demo.hello, " OK ", BtnHello, UL, 200, 180 Open "Cycling the Textboxes" for Window as #demo #demo, "Trapclose XbyTrap" #demo, "Font Times_New_Roman 12 Bold" #demo.tb1, "!Setfocus" Wait Sub XbyTrap handle$ Close #handle$ End End Sub Sub BtnCycle handle$ hFocusControl = FocusControl() Select Case hFocusControl Case hWnd(#demo.tb1) #demo.tb2, "!Setfocus" Case hWnd(#demo.tb2) #demo.tb3, "!Setfocus" Case hWnd(#demo.tb3) Call BtnHello, "#demo.hello" #demo.tb1, "!Setfocus" End Select End Sub Sub BtnHello handle$ Notice "Ok Button Pressed" End Sub ' FocusControl Function from Brad Moore's ' Liberty BASIC Newsletter Issue #98 Article ' Hocus Focus (Note change of Long to Ulong) Function FocusControl() CallDLL #user32, "GetFocus", _ FocusControl as Ulong End Function
|
|
curly
Full Member
Posts: 161
|
Post by curly on May 7, 2021 14:27:05 GMT -5
Hi,
Thank you - just printed both out and will analyse and learn over a wee glass of Scotlands best! (it is 8:30 pm here)
|
|
curly
Full Member
Posts: 161
|
Post by curly on May 8, 2021 10:46:24 GMT -5
Hi mknarr, all done and working fine, thank you very much.
|
|