| View previous topic :: View next topic |
| Author |
Message |
LiquidNeon Cheater
Reputation: 0
Joined: 26 Oct 2007 Posts: 32
|
Posted: Tue Jan 01, 2008 10:03 pm Post subject: [VB6] SendKeys Dilemma [Resolved] |
|
|
I've just started working on a private software project not long ago.
And now I'm stucked in the middle of the SendKeys thingy
My idea was to start up a selected application from my PC and then execute it by clicking on a button which also activates the timer and then sends programmed key inputs to the executed application without activating the executed application.
But, I somehow wasn't able to send the key inputs to the executed application.
This was my code
| Code: |
Private Sub aaa_Click()
Set wShell = CreateObject("WScript.Shell")
wShell = Shell("C:\WINDOWS\system32\notepad.exe", vbNormalFocus)
If wShell > 32 Then
If aaa.Value = 1 Then
Me.WindowState = vbMinimized
wShell.AppActivate ("Notepad")
WScript.Sleep 20
wShell.SendKeys ("OMG!")
End If
End If
End Sub
|
I've also tried this code.
| Code: |
Private Sub Button1_Click()
Dim L As Long
L = Shell("C:\WINDOWS\system32\notepad.exe", vbNormalFocus)
If L > 32 Then
If Command1.Value = 1 Then
Me.WindowState = vbMinimized
SendKeys ("OMG")
End If
End If
End Sub
|
Any help is very much appreciated.
Last edited by LiquidNeon on Wed Jan 02, 2008 7:22 am; edited 1 time in total |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Wed Jan 02, 2008 1:40 am Post subject: |
|
|
SendKeys does not work like that. It sends keys to the currently active application. AppActivate can be used to pull a given window to the front and give it focus to then send the keys via SendKeys.
You can look at the examples of PostMessage and SendInput that are posted here to do things a bit different.
_________________
- Retired. |
|
| Back to top |
|
 |
LiquidNeon Cheater
Reputation: 0
Joined: 26 Oct 2007 Posts: 32
|
Posted: Wed Jan 02, 2008 4:22 am Post subject: Ex. |
|
|
Examples please?
I've tried using Object.AppActivate ("AppName")
But however, it doesn't work.
|
|
| Back to top |
|
 |
Kerelmans Advanced Cheater
Reputation: 0
Joined: 29 Oct 2007 Posts: 57
|
Posted: Wed Jan 02, 2008 5:44 am Post subject: Sendkeys |
|
|
Hey, add a timer and a button to it, set timer interval to 1-1000 and the value to FALSE
add this code to your button:
command1_click ()
shell ("notepad.exe",vbnormalfocus)
timer1=1
end sub
Timer1 ()
sendkeys "put your text here"
timer1=0
end sub
this will write the text into notepad, after 1-1000 seconds!
|
|
| Back to top |
|
 |
LiquidNeon Cheater
Reputation: 0
Joined: 26 Oct 2007 Posts: 32
|
Posted: Wed Jan 02, 2008 7:16 am Post subject: Re: Sendkeys |
|
|
| Kerelmans wrote: | Hey, add a timer and a button to it, set timer interval to 1-1000 and the value to FALSE
add this code to your button:
command1_click ()
shell ("notepad.exe",vbnormalfocus)
timer1=1
end sub
Timer1 ()
sendkeys "put your text here"
timer1=0
end sub
this will write the text into notepad, after 1-1000 seconds! |
I lub j00!!!
Anyway, thanks.
(o 3 o)
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Wed Jan 02, 2008 10:35 am Post subject: |
|
|
Although you marked this as solved, heres a quick example:
| Code: | Private Sub Form_Load()
AppActivate "Notepad", 1000
SendKeys "This is a test.", 500
End Sub |
I suggest not using this method because the control to type in does not always get focus from AppActivate unless you gave it focus before minimizing it and such.
_________________
- Retired. |
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Wed Jan 02, 2008 12:16 pm Post subject: |
|
|
Use PostMessage or SendMessage. There is a parm thingy on msdn.
BTW. SOme1 with 1 post has rep o.o
|
|
| Back to top |
|
 |
|