简体   繁体   English

如何点击键盘上的回车键?

[英]How to click the enter button on the keyboard?

Is there a way to Click the ENTER key on the keyboard, other than SendKeys.Send("{ENTER}"? I have an Application I created in VB.net that will create a line of text then send it to another application with AppActivate, it works great when the receiving application was created in C++. But when the receiving application was created in Java the SendKeys.Send("{ENTER}" will not work. All the text is transferred to the Java application but the ENTER button will not click. Is there another way to Click ENTER on the Keyboard or simulate it?有没有办法单击键盘上的 ENTER 键,而不是 SendKeys.Send("{ENTER}"? 我有一个在 VB.net 中创建的应用程序,它将创建一行文本,然后使用 AppActivate 将其发送到另一个应用程序, 当接收应用程序是在 C++ 中创建时,它工作得很好。但是当接收应用程序是在 Java 中创建时, SendKeys.Send("{ENTER}" 将不起作用。所有文本都传输到 Java 应用程序,但 ENTER 按钮将不是单击。有没有其他方法可以单击键盘上的 ENTER 或模拟它?

Thank You谢谢你

Have you tried P/Invoke?你试过 P/Invoke 吗?

For example:例如:

<DllImport("user32.dll", SetLastError:=True, EntryPoint:="PostMessageA")>
Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Boolean

Public Const WM_KEYDOWN As Integer = &H0100 'Key Down Event
Public Const VK_RETURN As Integer = &H0D 'Enter Key

Public Shared Sub SendKeyDownEvent(ByVal hWnd As IntPtr, ByVal key As Integer)
    PostMessage(hWnd, WM_KEYDOWN, key, 0)
    System.Threading.Thread.Sleep(500)
End Sub

And you could call it like:你可以这样称呼它:

SendKeyDownEvent(handleToApplication, VK_RETURN)

There are plenty of resources available for obtaining handles to other applications:有大量资源可用于获取其他应用程序的句柄:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM