我想使用sendkeys将键击发送到远程终端应用程序。
这不起作用。
经过一些调查后,很明显这是一个相当普遍的问题。
我发现有人发布他们使用屏幕键盘模拟点击并成功将击键传递给远程机器。
这对我来说很有用,但我无法通过屏幕键盘来识别点击。
以下是一些代码,我只需尝试使用屏幕键盘将数字4输入到Excel中的单元格中。
代码移动到单元格A1并单击它,然后移动到osk上的数字4,但据我所知没有单击。
感谢您的帮助
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long,ByVal y As Long) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cbuttons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_LEFTDOWN As Integer = 2
Const MOUSEEVENTF_LEFTUP As Integer = 4
Private Type pointapi
x As Long
y As Long
End Type
Sub test()
' Cursor Position 61, 206 is cell A1 on the excel sheet
SetCursorPos 61, 206
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 'click left mouse
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 'release left mouse
' Cursor Position 255, 937 is the number 4 on the on screen keyboard
SetCursorPos 255, 937
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 'click left mouse
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 'release left mouse
End Sub
答案 0 :(得分:0)
如果您要输入内容,请使用“ sendkeys”
SendKeys "%fa~" 'works like Alt+f then Alt+a (File>Save As)
Sleep 500
SendKeys "Hurrah_" 'on the text field
Sleep 500