-
Jun 20th, 2022, 12:13 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Release Sendkeys to Edit my Application
Okay.
I have an application that I send keys (strings ) to, say Notepad.
It send a string to the last focus app. other than mine
All works fine
However, If I want to edit a text box on my application it still keeps sending key strings to notepad.
How do I release the current window that my app is talking too so I can edit my Textbox1.Text??
Code to capture window api.
Code:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Code:
Shared Function ReleaseCapture() As Boolean
>>>> WHAT GOES HERE so I can edit Textbox1 when it has focus??
End Function
Thanks in advanced.
Last edited by pixelink; Jun 20th, 2022 at 12:20 PM.
-
Jun 20th, 2022, 01:17 PM
#2
Re: Release Sendkeys to Edit my Application
Where/how are you calling the SendMessage method?
-
Jun 20th, 2022, 02:42 PM
#3
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
Code:
SendKeys.Send("^(v)")
I have an on screen keyboard.
-
Jun 20th, 2022, 02:43 PM
#4
Re: Release Sendkeys to Edit my Application
Right. And where are you calling that from?
-
Jun 20th, 2022, 02:44 PM
#5
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
Butons or clicking on a listbox item
Last edited by pixelink; Jun 20th, 2022 at 04:08 PM.
-
Jun 20th, 2022, 02:45 PM
#6
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
Like I said. The Sendkeys and communicating with other apps works great.
Its just trying to edit a Textbox on my own app after a link is established.
-
Jun 20th, 2022, 02:50 PM
#7
Re: Release Sendkeys to Edit my Application
That's fine. I wanted to rule out you calling this method in a timer or in a separate thread.
Looking at the documentation on the particular API I don't see anything that would hold the command. So at this point, it is a bit out of my wheelhouse. I'll let someone else chime in to see if they have experienced this issue.
-
Jun 20th, 2022, 02:50 PM
#8
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
I do notice if I do a refresh on my listbox or change a value in a dropdown, the link is broke and then I can edit my own textbox.
Or I can close the app and restart it. That breaks the link too.
But, is there a way to just set the main form and break the message link between my app and another easily?
-
Jun 20th, 2022, 02:55 PM
#9
Re: Release Sendkeys to Edit my Application
Edit: never mind, updates were made to the thread that made my post irrelevant.
-
Jun 20th, 2022, 03:03 PM
#10
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
I wonder, how do I make a call to re-paint the form. I wonder if that will work because it seems that picking an item from a dropdown combo box works.
-
Jun 20th, 2022, 03:13 PM
#11
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
-
Jun 20th, 2022, 03:19 PM
#12
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
Hmm... I just put a button on the form and displayed a Messagebox. That breaks the link.
So, how can I invoke something that I don't have to respond to or click, i.e. like a dropdown combo box?
Last edited by pixelink; Jun 20th, 2022 at 03:37 PM.
-
Jun 20th, 2022, 03:53 PM
#13
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
So, the more I try different ways to refresh the form.
It seems that mouse interaction is required with a message box, my own modal form or a dropdown box.
There has to be a better way to break the link to other apps from my own form.
Last edited by pixelink; Jun 21st, 2022 at 02:00 PM.
-
Jun 21st, 2022, 10:04 AM
#14
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
Still looking for a solution
-
Jun 21st, 2022, 02:59 PM
#15
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
Still looking for a solution to this issue.
-
Jun 21st, 2022, 05:02 PM
#16
Thread Starter
Addicted Member
Re: Release Sendkeys to Edit my Application
I figured it out.
I had to force my app which was already in the foreground (and topmost)
to be the actual foreground app that has focus.
Even though I would click inside the Textbox, because Notepad was the actual foreground app in the thread,
I had to force it to be the foreground in the thread.
Code:
'setforegroundowindow
Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Public Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Integer) As Boolean
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
Public Const SW_RESTORE As Integer = 9
Public Const SW_SHOW As Integer = 5
'setforegroundowindow
Sub FocusWindow(ByVal strWindowCaption As String, ByVal strClassName As String)
Dim hWnd As Integer
hWnd = FindWindow(strClassName, strWindowCaption)
If hWnd > 0 Then
SetForegroundWindow(hWnd)
If IsIconic(hWnd) Then 'Restore if minimized
ShowWindow(hWnd, SW_RESTORE)
Else
ShowWindow(hWnd, SW_SHOW)
End If
End If
End Sub
Code:
Private Sub txtEditor_Enter(sender As Object, e As EventArgs) Handles txtEditor.Enter
'setforegroundowindow to my app
FocusWindow("Desktop Tasks", Nothing)
End Sub
Last edited by pixelink; Jun 21st, 2022 at 05:05 PM.
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
|