简体   繁体   中英

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?

Thank You

Have you tried 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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