Results 1 to 5 of 5

Thread: Emulate real keyboard key press

  1. #1

    Thread Starter
    Junior Member asasino's Avatar
    Join Date
    Nov 2007
    Posts
    24

    Lightbulb 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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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.

  3. #3

    Thread Starter
    Junior Member asasino's Avatar
    Join Date
    Nov 2007
    Posts
    24

    Re: Emulate real keyboard key press

    Quote Originally Posted by .paul. View Post
    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.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Emulate real keyboard key press

    if that doesn't help, could you post a screenshot of your Flight Simulator window?

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
  •  



Click Here to Expand Forum to Full Width