In context of the posting from mic jones
here I check different ways of SendKey from an Excel VBA application to a session window.
At first I identfiy the handle of the session window and set it in foreground with the following code
Private Declare Function SetForegroundWindow Lib "user32.dll" _
(ByVal hWnd As Long) As Long
hWnd = Session.ActiveWindow.Handle
SetForegroundWindow hWnd
After that I use different methods of SendKeys:
- Standard VBA SendKeys, but it doesn't work.SendKeys "+{DOWN}", True
- SendKeys via SendMessage, but it doesn't work.Private Declare Function SendMessageA Lib "user32.dll" _
(ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
SendMessageA hWnd, &H100, vbKeyShift, 0
SendMessageA hWnd, &H100, vbKeyDown, 0
SendMessageA hWnd, &H101, vbKeyDown, 0
SendMessageA hWnd, &H101, vbKeyShift, 0
DoEvents
- SendKeys via keybd_event, but it doesn't work.Private Declare Sub keybd_event Lib "user32.dll" _
(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
keybd_event &H10, 0, 0, 0
keybd_event &H28, 0, 0, 0
keybd_event &H28, 0, 2, 0
keybd_event &H10, 0, 2, 0
- SendKeys via Windows Scripting Host and this works very fine.Dim wsh As WshShell
Set wsh = CreateObject("WScript.Shell")
wsh.SendKeys "+{DOWN}"
Maybe someone can use this information or show different ways.