|
-
Mar 2nd, 2004, 06:00 AM
#1
Thread Starter
Frenzied Member
Keypress ?
How do i get a keypress to simulate ?
Like i have this old comp games that you need to press 'o' for left and 'p' for right. so i want to be able to click a command button that will press these keys for me alternating in a loop. I also want to be able to increase the speed of this alternation .
any ideas ?
-
Mar 2nd, 2004, 06:20 AM
#2
Frenzied Member
Look at SendKeys in the help files.
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Mar 2nd, 2004, 06:33 AM
#3
Thread Starter
Frenzied Member
Ok thanks.
Do i need to code it so that the keys will be send to the app that run this game or how does it work ?
-
Mar 2nd, 2004, 09:05 AM
#4
Frenzied Member
May want to look into a Macro program also, it can do all that for you.
-
Mar 2nd, 2004, 09:12 AM
#5
-
Mar 2nd, 2004, 09:15 AM
#6
Frenzied Member
Start a form, and put a Timer control on it from the toolbox.
Set the timer's Enabled property to False, and set the Interval property to 500
Also put a button on the form, and in the Click event of the button:
VB Code:
Private Sub Command1_Click()
If Timer1.Enabled = True Then
Timer1.Enabled = False
Else
AppActivate "Microsoft Word", True
Timer1.Enabled = True
End If
End Sub
I've used Microsoft Word here - but if you put the title of the program (what appears in the title bar of the window) this should work.
Then, in the Timer event of the timer control:
VB Code:
Private Sub Timer1_Timer()
Static LastKey As String
If LastKey = "O" Then
SendKeys "P", True
LastKey = "P"
Else
SendKeys "O", True
LastKey = "O"
End If
DoEvents
End Sub
This will send the O and P keypresses to the activated application (in my case, Microsoft Word). Use the button to switch the timer on or off.
Vary the Interval property of the timer to speed up / slow down the keypresses. (a smaller number is faster)
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Mar 2nd, 2004, 10:45 AM
#7
Thread Starter
Frenzied Member
Originally posted by Buzby
Start a form, and put a Timer control on it from the toolbox.
Set the timer's Enabled property to False, and set the Interval property to 500
Also put a button on the form, and in the Click event of the button:
VB Code:
Private Sub Command1_Click()
If Timer1.Enabled = True Then
Timer1.Enabled = False
Else
AppActivate "Microsoft Word", True
Timer1.Enabled = True
End If
End Sub
I've used Microsoft Word here - but if you put the title of the program (what appears in the title bar of the window) this should work.
Then, in the Timer event of the timer control:
VB Code:
Private Sub Timer1_Timer()
Static LastKey As String
If LastKey = "O" Then
SendKeys "P", True
LastKey = "P"
Else
SendKeys "O", True
LastKey = "O"
End If
DoEvents
End Sub
This will send the O and P keypresses to the activated application (in my case, Microsoft Word). Use the button to switch the timer on or off.
Vary the Interval property of the timer to speed up / slow down the keypresses. (a smaller number is faster)
Perfect ! thanks.
-
Mar 2nd, 2004, 09:13 PM
#8
Thread Starter
Frenzied Member
Ok this doesnt actually server my purpose.
I want to shell cmd then run a command in it, then when that command has finished running, do something else,
shellandwait "cmd /k netstat-n"
shell "shutdown.exe -s"
but if using shellandwait it waits for cmd to be shut down before i can progress in my code if that makes sense ?
-
Mar 3rd, 2004, 04:18 AM
#9
Frenzied Member
Try using
shellandwait "cmd /C netstat-n"
having a /K in there makes the window stay open after the cmd has finished - putting a /C in there makes the window close.
I'm confused.. what does this have to do with SendKeys ?
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
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
|