[RESOLVED] Help how to simulate sendkeys in Vista?
I've been using this code for ages in triggering TAB in VB6 using XP as my OS.
sendkeys Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
SendKeys vbTab
End If
End Sub
I'm using Vista Business now as my OS and I'm having error problems with the code above. Is there a way to to use the code above in vista? or can you suggest an API that I can use for vista? Any help is greatly appreciated.
Re: Help how to simulate sendkeys in Vista?
SendKeys isnt supported in Vista. You can use the SendMessage or PostMessage aPIs to replicate the message.
Re: Help how to simulate sendkeys in Vista?
tnx for the reply. can you point me to a link for a sample code? tnx.
Re: Help how to simulate sendkeys in Vista?
You need to use the keybd API
Code:
'Declares to include
Private Const VK_TAB = &H9
Private Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
'heres the command to call
keybd_event VK_TAB, 0, 0, 0 'send a tab
Re: Help how to simulate sendkeys in Vista?
keybd_event requires input focus same as sendkeys but for the most stable method, see the APIs listed at http://allapi.mentalis.org.
Re: Help how to simulate sendkeys in Vista?
Re: Help how to simulate sendkeys in Vista?
thank you RobDog888 the api guild there is a big help
Quote:
Originally Posted by RobDog888
keybd_event requires input focus same as sendkeys but for the most stable method, see the APIs listed at http://allapi.mentalis.org.
Re: Help how to simulate sendkeys in Vista?
I found this code here in vbforums. Works great.
Save the code below to a module
Module Code:
Option Explicit
Private Const KEYEVENTF_KEYUP = &H2
Private Const INPUT_KEYBOARD = 1
Private Type KEYBDINPUT
wVk As Integer
wScan As Integer
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type GENERALINPUT
dwType As Long
xi(0 To 23) As Byte
End Type
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Public Function SendKeysA(ByVal vKey As Integer, Optional booDown As Boolean = False)
Dim GInput(0) As GENERALINPUT
Dim KInput As KEYBDINPUT
KInput.wVk = vKey
If Not booDown Then
KInput.dwFlags = KEYEVENTF_KEYUP
End If
GInput(0).dwType = INPUT_KEYBOARD
CopyMemory GInput(0).xi(0), KInput, Len(KInput)
Call SendInput(1, GInput(0), Len(GInput(0)))
End Function
Then put this code to a form. Be sure the KEY PREVIEW of the form is set to TRUE