-
Feb 11th, 2020, 08:53 AM
#1
Thread Starter
Junior Member
[RESOLVED] Inputbox not ready for input after form got focus
i'm using the following call:
Code:
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
running on a timer, to check for an 'F10' keypress. While my app does not have the focus (is in background somewhere,not minimized)
When the key is pressed, I Show the form and setfocus to it, then ask for userinput.
But the inputbox is not ready to receive input, and it still needs a manual click to be able to receive input.
i tried:
Code:
Form1.Show
Form1.SetFocus
'DoEvents
'Ask for filename
Filename$ = InputBox("Input Filename: when no name is given+(OK), a date and time will be used", "Save image to file") 'Ask for filename
and API call:
Code:
'Set Form1 Topmost
Call SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
'Ask for filename
Filename$ = InputBox("Input Filename: when no name is given+(OK), a date and time will be used", "Save image to file") 'Ask for filename
'Check for input, ok or cancel
If StrPtr(Filename$) = 0 Then 'Checks if cancel was pressed
'User pressed cancel
Form1.Label1.Caption = "User canceled filename input."
Exit Function
ElseIf Filename$ = "" Then 'User provided no input but clicked 'OK'
Filename$ = Replace(Now(), ":", "-")
End If
'Return Form1 NotTopMost
Call SetWindowPos(Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
i was expecting the inputbox to be available immediately, but it somehow isn't. The problem is not there when form1 already has the focus while F10 is pressed.
What could be the cause, or how can i achieve it to be ready for input without interaction
-
Feb 11th, 2020, 11:18 AM
#2
Re: Inputbox not ready for input after form got focus
Form1 can't show itself immediately, to take the focus, i.e. you have to stop running user code by exiting the sub so that the form can accept the focus.
After the form is the active window it can open the input dialog which will take the focus from the form.
It looks like you tried 'DoEvents', which may work on occasion, but perhaps there are several events involved in getting the form to become active, and a single DoEvents doesn't allow for all of them to occur, there may be delays involved between the events necessary to activate a window.
Perhaps if you have the code in a timer event, and enable the timer, which shows and processes the input dialog after a short delay, which allows the form to become active before you get the tick.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Feb 11th, 2020, 07:34 PM
#3
Re: Inputbox not ready for input after form got focus
Did you try AppActivate? See vb help.
-
Feb 12th, 2020, 07:17 AM
#4
Thread Starter
Junior Member
Re: Inputbox not ready for input after form got focus
This worked instantly.
Code:
AppActivate Form1.Caption
Thanks for that.
-
Feb 12th, 2020, 07:34 AM
#5
Re: Inputbox not ready for input after form got focus
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|