|
-
Jan 21st, 2010, 09:02 AM
#1
Thread Starter
New Member
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.
-
Jan 21st, 2010, 10:20 AM
#2
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()
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jan 21st, 2010, 10:38 AM
#3
Thread Starter
New Member
Re: Send keys to application what's not in focus.
oh, Im too big nub to understand this.
Vb saying FindWindow is not declerated
-
Jan 21st, 2010, 10:40 AM
#4
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
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jan 21st, 2010, 10:45 AM
#5
Hyperactive Member
Re: Send keys to application what's not in focus.
 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.
-
Jan 21st, 2010, 10:55 AM
#6
Thread Starter
New Member
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
-
Jan 21st, 2010, 11:01 AM
#7
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
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jan 21st, 2010, 11:09 AM
#8
Thread Starter
New Member
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?
-
Jan 21st, 2010, 11:13 AM
#9
Hyperactive Member
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
-
Jan 21st, 2010, 11:19 AM
#10
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
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jan 21st, 2010, 11:19 AM
#11
Thread Starter
New Member
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.
-
Jan 21st, 2010, 11:35 AM
#12
Thread Starter
New Member
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.
Last edited by DynLV; Jan 21st, 2010 at 12:03 PM.
-
Jan 21st, 2010, 12:00 PM
#13
Re: Send keys to application what's not in focus.
 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.
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.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 21st, 2010, 12:02 PM
#14
Re: Send keys to application what's not in focus.
 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.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 21st, 2010, 12:44 PM
#15
Thread Starter
New Member
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
-
Jan 21st, 2010, 01:52 PM
#16
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.
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jan 21st, 2010, 02:20 PM
#17
Re: Send keys to application what's not in focus.
 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.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 22nd, 2010, 08:08 AM
#18
Thread Starter
New Member
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
-
Jan 22nd, 2010, 03:23 PM
#19
Hyperactive Member
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
-
Jan 23rd, 2010, 05:36 AM
#20
Thread Starter
New Member
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.
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
|