Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force keypress

Status
Not open for further replies.

steinmag

Instructor
Nov 30, 2001
4
NO
I'm making a program which will simulate a keypress after a spesific number of times. I'have tried SendKeys but it doesn't work. The problem here (I think) is than SendKeys doesn't actually "press" the key, but only sends the Ascii value back. Am I right? How can I accomplish this?
 
Add a text box and a command button to a form then drop in this code

Option Explicit

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)

Private Const VK_C = &H43
Private Const KEYEVENTF_KEYUP = &H2

Private Sub Command1_Click()
Text1.SetFocus
keybd_event VK_C, 0, 0, 0
keybd_event VK_C, 0, KEYEVENTF_KEYUP, 0
End Sub

This is just a quick code sample. You will need to add the Virtual Key Constants for the keys that you want. Hope this helps. If you choose to battle wits with the witless be prepared to lose.
[machinegun][ducky]
 
A simpler approach may be to just add a counter. If you
just decrement the counter each time, then test if it's
reached zero - then do something if it has.

smile.gif
 
[bugeyed] ? [spineyes] If you choose to battle wits with the witless be prepared to lose.
[machinegun][ducky]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top