0

I'm developing my own onscreen keyboard using vb.net

I need a lower level keyboard, that can write in every process. write on a new notepad file i used this code:

    Dim hwnd As IntPtr = FindWindow(Nothing, "Untitled - Notepad")

    If Not hwnd = IntPtr.Zero Then
        SetForegroundWindow(hwnd)
        SetFocus(hwnd)

        keybd_event(VK_RETURN, 0, 0, 0)
        Thread.Sleep(100)
        keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0)

    End If

But i need that this keyboard write in every kind of text editor and file name (not only in file "untitled - Notepad")

How can i focus on last process before geting focus on my form?

Thanks a lot

  • 1
    The mistake you're making is that your you are stealing focus in the first place. You shouldn't have to work out what window HAD focus because it should still HAVE focus because you shouldn't be TAKING focus. You might want to [check this out](http://www.vbforums.com/showthread.php?459890). – jmcilhinney Oct 03 '18 at 10:11
  • Ok,thank you. I solved this problem – Davide Redaelli Oct 03 '18 at 11:42

2 Answers2

0

Make it so that your on-screen keyboard does not get focus to begin with, then write to to currently focused window.

See https://www.codeproject.com/Articles/71808/Creating-a-Form-That-Doesn-t-Take-Focus for WinForms or Not take focus, but allow interaction? for WPF.

viking_grll
  • 131
  • 8
0

Problem is solved looking at http://www.vbforums.com/showthread.php?459890

vb.net onscreen keyboard form must not take focus.