|
-
Jul 12th, 2014, 03:35 PM
#1
Thread Starter
Junior Member
Emulate real keyboard key press
Here is a quick description of my problem:
I am trying to connect my Arduino programmable board with Microsoft Flight Simulator (3D) using vb.net app to communicate between them.
By rotating the encoder on the Arduino, board sends a signal via COM (USB) port to the computer. My vb.net application reads the port and needs to send a keystroke to Flight Simulator.
I have already tried using the "send key" function:
Code:
SetForegroundWindow(FsimHandle)
SendKeys.SendWait("h")
I do get output in Notepad and similar programs, but my Flight Simulator (ran in windowed mode) simply does not register it. If I try using the MS On-screen keyboard, however, I do get the desired effect. Also pressing the key on the real keyboard works :
The problem is that Flight Simulator only accepts KEY inputs, and I just don't know how to implement this using vb.net.
Kindest regards,
Nikola
-
Jul 12th, 2014, 04:36 PM
#2
Re: Emulate real keyboard key press
SendKeys sends keystrokes to the currently active window. if your arduino controller has a window, there are other methods available too.
First try giving focus to the window before SendKeys:
AppActivate("window title")
or:
AppActivate(window handle)
edit: it's the edit control that needs to be focussed
Last edited by .paul.; Jul 12th, 2014 at 04:41 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 12th, 2014, 04:48 PM
#3
Thread Starter
Junior Member
Re: Emulate real keyboard key press
 Originally Posted by .paul.
edit: it's the edit control that needs to be focussed
Thank you for replying,
I did not really understand what you mean by this ^
I have tried AppActivate function, but only thing it does is focus the Flight Simulator window. Unfortunately no keys are passed on.
A virtual keyboard would be a perfect solution, only I don't know does such thing exist.
-
Jul 12th, 2014, 05:22 PM
#4
Re: Emulate real keyboard key press
ok. try this:
Code:
Public Class Form1
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Const WM_SETTEXT As Integer = &HC
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMessage(windowHandle, WM_SETTEXT, 0, "h")
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 12th, 2014, 05:25 PM
#5
Re: Emulate real keyboard key press
if that doesn't help, could you post a screenshot of your Flight Simulator window?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|