|
-
Nov 23rd, 2006, 06:18 PM
#1
Thread Starter
New Member
Help with Sendkeys command
this is probably a n00b question
I want to have a program , that after clicking a button on a form (could be called "Go") repeatedly simulates the pressing of a key on the keyboard until it is told to stop.
I can work it all out apart from how to code the keyboard press.
Can anyone help please
Thanks
Last edited by paulrg; Nov 24th, 2006 at 11:57 AM.
Reason: Changed topic as per request
-
Nov 23rd, 2006, 06:26 PM
#2
Re: Please help
Sendkeys("a")
that would send the a letter to whatever app was in focus
-
Nov 23rd, 2006, 06:41 PM
#3
Re: Please help
Welcome to VBF Paul. 
Please give your topics a useful title, everyone needs help.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Nov 23rd, 2006, 07:11 PM
#4
Re: Please help
Name your CommandButton "cmdGo" and try this:
VB Code:
Option Explicit
Private Sub Form_Load()
cmdGo.Caption = "Go"
End Sub
Private Sub cmdGo_Click()
If cmdGo.Caption = "Go" Then
cmdGo.Caption = "Stop"
Else
cmdGo.Caption = "Go"
End If
Do Until cmdGo.Caption = "Go"
SendKeys "a", True
DoEvents
Loop
End Sub
And welcome to VBForums
-
Nov 23rd, 2006, 07:15 PM
#5
Re: Please help
 Originally Posted by gavio
Name your CommandButton "cmdGo" and try this:
VB Code:
Option Explicit
Private Sub Form_Load()
cmdGo.Caption = "Go"
End Sub
Private Sub cmdGo_Click()
If cmdGo.Caption = "Go" Then
cmdGo.Caption = "Stop"
Else
cmdGo.Caption = "Go"
End If
Do Until cmdGo.Caption = "Go"
SendKeys "a", True
DoEvents
Loop
End Sub
And welcome to VBForums 
Wow the code I was going to post was exactly the same as yours.
-
Nov 23rd, 2006, 07:17 PM
#6
Re: Please help
 Originally Posted by DigiRev
Wow the code I was going to post was exactly the same as yours. 

I found this peace of code to be... anoying... my notebook ventilator just sang like a canarian...
-
Nov 23rd, 2006, 07:36 PM
#7
Thread Starter
New Member
Re: Please help
thats excellent , just what I was after 
thanks guys
-
Nov 23rd, 2006, 07:47 PM
#8
Re: Please help
you can use a timer to provide an interval after you click go, because you probably dont want to send key presses to your form or button
-
Nov 24th, 2006, 11:56 AM
#9
Thread Starter
New Member
Re: Please help
Yes ive used a timer to do this
like this
Private Sub Timer1_Timer()
SendKeys "4"
End Sub
The program works fine when I run it and then load up notepad. But when I try to run the game im trying to get this to run with it doesnt work , almost as if the game doesnt have focus.
Anyone have any thoughts?
Great stuff so far though
-
Nov 24th, 2006, 12:22 PM
#10
New Member
Re: Help with Sendkeys command
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
|