|
-
Feb 26th, 2011, 01:10 PM
#1
Thread Starter
Junior Member
How to send a key to a minimized window
im pretty new here and i hope i posted in the correct section . if not im sorry.
But i have a problem so i want to Send one key to a minimized form if u know what i mean like running it in the background its the key "F5" that i want to send
. It works if the window is focused but as soon as i start my internet it refreshs the sites there and not where it was ment to be .
I hope anyone can help me .
-
Feb 26th, 2011, 07:38 PM
#2
Thread Starter
Junior Member
Re: How to send a key to a minimized window
-
Feb 26th, 2011, 08:53 PM
#3
Re: How to send a key to a minimized window
How are you sending the program the F5 key now?
If you know the handle of the window that is accepting keys (could be the main window or an edit window, etc, ) then sending the key down/up to that handle may work. For example I have a VB6 app that has its form set to KeyPreview = True so it detects keys pressed on it, lets call it "VB6-TestApp", even when minimized it detects the F5 key sent to it from this VB10 code...
Code:
Public Class Form1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Const WM_KEYUP As Integer = &H101
Private Const WM_KEYDOWN As Integer = &H100
Private Const VK_F5 As Integer = &H74 ' http://msdn.microsoft.com/en-us/library/dd375731%28v=vs.85%29.aspx
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' find window with title bar text "VB6-TestApp"
Dim r As IntPtr = FindWindow(Nothing, "VB6-TestApp")
' if window found Send F5 to the handle
If r.ToInt32 <> 0 Then 'Debug.Print("Window found!")
PostMessage(r, WM_KEYDOWN, VK_F5, 0)
PostMessage(r, WM_KEYUP, VK_F5, 0)
Else
Debug.Print("Window NOT found!")
End If
End Sub
End Class
-
Feb 27th, 2011, 03:57 AM
#4
Thread Starter
Junior Member
Re: How to send a key to a minimized window
 Originally Posted by Edgemeal
How are you sending the program the F5 key now?
If you know the handle of the window that is accepting keys (could be the main window or an edit window, etc, ) then sending the key down/up to that handle may work. For example I have a VB6 app that has its form set to KeyPreview = True so it detects keys pressed on it, lets call it "VB6-TestApp", even when minimized it detects the F5 key sent to it from this VB10 code...
ok sounds good im sending it with a timer to the program with sendkeys.send
I will try this now
-
Feb 27th, 2011, 12:04 PM
#5
Thread Starter
Junior Member
Re: How to send a key to a minimized window
hmm i dont know it doesnt work fine ... 
i just want to make a project that refreshes the website after 9 seconds also if it is minimized
But now it doesnt send keys at all
-
Feb 28th, 2011, 12:51 AM
#6
Junior Member
Re: How to send a key to a minimized window
Try This. SendKeys.Send("{F5}").
-
Feb 28th, 2011, 05:17 AM
#7
Thread Starter
Junior Member
Re: How to send a key to a minimized window
 Originally Posted by Marvin777
Try This. SendKeys.Send("{F5}").
Thats what i had before but then it works for every window not just in my application....
-
Feb 28th, 2011, 10:32 AM
#8
Re: How to send a key to a minimized window
 Originally Posted by killerrj8
hmm i dont know it doesnt work fine ... 
i just want to make a project that refreshes the website after 9 seconds also if it is minimized
But now it doesnt send keys at all 
Then you're probably using the wrong handle in that code. If it is a web browser control on a VB form you are trying to send the F5 key to then you need to use the web browser control handle, not the forms handle.
If you just need to refresh after 9 seconds then why not just add a timer that runs once, set timer to 9000 and start it when that certain URL is detected in the browser or something.
-
Feb 28th, 2011, 01:25 PM
#9
Thread Starter
Junior Member
Re: How to send a key to a minimized window
 Originally Posted by Edgemeal
Then you're probably using the wrong handle in that code. If it is a web browser control on a VB form you are trying to send the F5 key to then you need to use the web browser control handle, not the forms handle.
If you just need to refresh after 9 seconds then why not just add a timer that runs once, set timer to 9000 and start it when that certain URL is detected in the browser or something.
And how can i focuse on the webbrowser ?
Im not that good in programming sry
-
Feb 28th, 2011, 09:53 PM
#10
Re: How to send a key to a minimized window
 Originally Posted by killerrj8
And how can i focuse on the webbrowser ?
Im not that good in programming sry
When you post/send a message to a control handle the control normally doesn't need to have focus, it only needs to accept/support the messages sent to it.
If you made both apps then a simple way around it is to just have your browser app save the web browser control handle when it starts up somewhere, like the registry, or a file, etc,. Now your other VB apps just need to retrieve that handle value from where the browser app saved it.
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
|