E
ekg
I want to use SendInput to send keystrokes and mouseclicks from ACCESS to
another application. I am trying first to send some text to a text box that
already has the focus in the current form. However when the API call is
executed I get a "bad API call" error. As far as I can tell the declarations
and datatypes are correct, but obviously I've missed something. Can anyone
advise what could be wrong? The database is in ACCESS 2003, but set up as
ACCESS 2000 (for backward compatibility), the OS is XP SP2. The code is
currently as follows. I use a command button to run Simkeys, which is
supposed to send the letter c to the textbox which has the focus on the same
form.:
Option Compare Database
Option Explicit
'
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 GetKeyboardState Lib "user32" (pbKeyState As Byte)
As Long
Private Declare Function SetKeyboardState Lib "user32" (llpbKeyState As
Byte) As Long
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long,
pInputs As GENERALINPUT, ByVal cbsize As Long)
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
(pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Simkeys()
Dim GInput(0 To 1) As GENERALINPUT
Dim KInput As KEYBDINPUT, nInputs As Long
Dim bKey As Byte
bKey = vbKeyC
nInputs = 2
' Code for Pressing Key
KInput.wVk = bKey 'Key value
KInput.dwFlags = 0 'Press the key
GInput(0).dwType = 1 'Keyboard input
CopyMemory GInput(0).xi(0), KInput, Len(KInput)
' Code for Releasing Key
KInput.wVk = bKey 'Key value
KInput.dwFlags = &H2 'Release the key
GInput(1).dwType = 1 'Keyboard input
CopyMemory GInput(1).xi(0), KInput, Len(KInput)
' Send Input to message stream of thread
SendInput nInputs, GInput(0), Len(GInput(0))
'
End Sub
another application. I am trying first to send some text to a text box that
already has the focus in the current form. However when the API call is
executed I get a "bad API call" error. As far as I can tell the declarations
and datatypes are correct, but obviously I've missed something. Can anyone
advise what could be wrong? The database is in ACCESS 2003, but set up as
ACCESS 2000 (for backward compatibility), the OS is XP SP2. The code is
currently as follows. I use a command button to run Simkeys, which is
supposed to send the letter c to the textbox which has the focus on the same
form.:
Option Compare Database
Option Explicit
'
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 GetKeyboardState Lib "user32" (pbKeyState As Byte)
As Long
Private Declare Function SetKeyboardState Lib "user32" (llpbKeyState As
Byte) As Long
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long,
pInputs As GENERALINPUT, ByVal cbsize As Long)
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
(pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Simkeys()
Dim GInput(0 To 1) As GENERALINPUT
Dim KInput As KEYBDINPUT, nInputs As Long
Dim bKey As Byte
bKey = vbKeyC
nInputs = 2
' Code for Pressing Key
KInput.wVk = bKey 'Key value
KInput.dwFlags = 0 'Press the key
GInput(0).dwType = 1 'Keyboard input
CopyMemory GInput(0).xi(0), KInput, Len(KInput)
' Code for Releasing Key
KInput.wVk = bKey 'Key value
KInput.dwFlags = &H2 'Release the key
GInput(1).dwType = 1 'Keyboard input
CopyMemory GInput(1).xi(0), KInput, Len(KInput)
' Send Input to message stream of thread
SendInput nInputs, GInput(0), Len(GInput(0))
'
End Sub