New
#21
SendKeys does not work, but it appears the API function SendInput does.
If you're in VB6, copy/paste this code into a module:
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 Const INPUT_KEYBOARD = 1
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)
' Overrides VBA.SendKeys, which throws Permission Denied error in Windows 10
Public Function SendKeys(ByVal Text As String)
Dim n As Long
For n = 1 To Len(Text)
SendKeysA Asc(Mid(Text, n, 1))
Next
End Function
' Send keycode
Public Function SendKeysA(ByVal vKey As Integer)
Dim GInput(0) As GENERALINPUT
Dim KInput As KEYBDINPUT
KInput.wVk = vKey
GInput(0).dwType = INPUT_KEYBOARD
CopyMemory GInput(0).xi(0), KInput, Len(KInput)
Call SendInput(1, GInput(0), Len(GInput(0)))
End Function