Send keys to application what's not in focus.
Hello, guys.
Im newbie in vb, so be nice to me pls.
I want to know how to send keys to some application, for example,
minimized notepad.
I have searched in google, youtube and this forum too.
Ppl saying that with Sendkeys.send you can only send keys to application what is in focus of screen. So, can anybody post code here for sending keys to application? Please.
Thanks. Dyn.
Re: Send keys to application what's not in focus.
I think that you can find and give the focus to a specific application window using its window title.
VB.NET Code:
Dim HWND As IntPtr
Dim windowTitle As String
HWND = FindWindow(Nothing, windowTitle )
If HWND.ToString() <> "0" Then
SetForegroundWindow(HWND)
End If
then you can send your keys using SendKeys.SendWait()
Re: Send keys to application what's not in focus.
oh, Im too big nub to understand this.
Vb saying FindWindow is not declerated :(
Re: Send keys to application what's not in focus.
Sorry, I totally forgot that you need to declare those two functions globally:
vb.net Code:
Private Declare Auto Function FindWindow Lib "user32" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As System.IntPtr) As Integer
Re: Send keys to application what's not in focus.
Quote:
Originally Posted by
stlaural
Sorry, I totally forgot that you need to declare those two functions globally:
vb.net Code:
Private Declare Auto Function FindWindow Lib "user32" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As System.IntPtr) As Integer
it depends where he declare them, i think.
in your code it seems it was declared in a form, because it's local.
Re: Send keys to application what's not in focus.
Yep, that's my next question xD
Where I need to place this code?
link for image - http://img715.imageshack.us/img715/9589/errorc.png
Re: Send keys to application what's not in focus.
I think it's ok where you declared it but you wrote :
Code:
Private Declare Function SetForegroundWindow Lib "user32" ()
ByVal hwnd As System.IntPtr As Integer
where you should have written :
Code:
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As System.IntPtr) As Integer
Re: Send keys to application what's not in focus.
Oh, sorry.
Now it looks fine, but how to make it to send the keys to application?
Re: Send keys to application what's not in focus.
so now you need to find the window, set it foreground
(as in the code above)
then sendkeys
the keys should be send to this window
Re: Send keys to application what's not in focus.
Now you can use SendKey methods.
Have a look at those two msdn pages :
SendKeys class
SendKeys.SendWait Method
Re: Send keys to application what's not in focus.
ooh, do this code will focus my window?
Very big thanks for helping, but then this code isnt for me, because I want to send keys to minimized application.
Hmm how to explain... For example, while Im writing a new message here, the program will keep sending keys to some application.
Re: Send keys to application what's not in focus.
eh, Im too big nub.
looks like I cant do anything more than copy/paste the code.
I rly dont understand what I should do now ;(
To make a program what sends keys to application whats in focus is easy, but this is too hard for me.
Sry all for wasting your time.
If some1 can show me a video tutorial or upload vb project that would be awesome. Thanks anyway.
Re: Send keys to application what's not in focus.
Quote:
Originally Posted by
DynLV
ooh, do this code will focus my window?
Very big thanks for helping, but then this code isnt for me, because I want to send keys to minimized application.
Hmm how to explain... For example, while Im writing a new message here, the program will keep sending keys to some application.
There are some things you need to know that have been assumed. First, in order to SendKeys to an application, it has to be in focus. That is why they have been showing you how to use the SetForegroundWindow API. Once it's in focus, you can send the required keys.
Quote:
I think it's ok where you declared it but you wrote :
Code:
Private Declare Function SetForegroundWindow Lib "user32" ()
ByVal hwnd As System.IntPtr As Integer
where you should have written :
Code:
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As System.IntPtr) As Integer
The reason why the underscore must appear there, in this instance, is because the User is creating a new line of existing code. Basically he did it for readability. You could just continue the line like so:
VB.NET Code:
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As System.IntPtr) As Integer
From there, you can do as you need.
Re: Send keys to application what's not in focus.
Quote:
Originally Posted by
DynLV
eh, Im too big nub.
looks like I cant do anything more than copy/paste the code.
I rly dont understand what I should do now ;(
To make a program what sends keys to application whats in focus is easy, but this is too hard for me.
Sry all for wasting your time.
It's never a waste of time. Using Windows' APIs can be difficult, especially if you're just starting. It's wise of you to know you've bitten off more than you can chew. Most people don't realize this, they get frustrated, and give up altogether.
Pick an easier project and once you begin to learn, things like this will come naturally.
Re: Send keys to application what's not in focus.
I think there isnt anything hard if some1 has made a tutorial xD
I made a program like this what send keys + have hotkeys + system tray icon + options in about 1h (my first program xD). All was easy cuz all what I needed i got in youtube videos. now only need to know how to send keys to minimized application.
Im saw program like mine where you can choose process from list box and then the program send keys to that process. but I dont remember the program name so I tried to create myself xD
Re: Send keys to application what's not in focus.
@weirddemon: thanks for the clarifications.
The only way I know to send keys to an application needs the said application to have focus.
Re: Send keys to application what's not in focus.
Quote:
Originally Posted by
stlaural
@weirddemon: thanks for the clarifications.
The only way I know to send keys to an application needs the said application to have focus.
That's the same as I thought. I wasn't aware of a method of sending keys to an application that isn't in focus. I've never seen it, but that doesn't mean it's impossible.
Re: Send keys to application what's not in focus.
Hmm, oke. I will try to search more for this thing.
Anyway, if some1 know please send me PM or write here. Thanks :)
Re: Send keys to application what's not in focus.
what application? it depends alot on the design of the app you are sending to
Re: Send keys to application what's not in focus.
It's game. KalOnline.
I think it not matter how looks the app, cuz my program will not write smth in chat but send keys for action in game.
Like trainer for GTA VC is sending keys ASPIRINE to replenish health.