write a new keyboard driver for software keyboard(XP)

I have created a software keyboard. I need to know how to use this to control (office) applications instead of the regular keyboard. Maybe I need to figure out how to create plugins?
softspotAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Ok...one solution is to make so that your keyboard app CANNOT receive focus.  Then when the user selects a key you can use SendKeys.Send() and whatever app was the foreground app will receive the keystroke (because clicking your app doesn't steal focus).

This is accomplished with the WS_EX_NOACTIVATE flag:
http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx

    "Windows 2000/XP: A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window."

Here is an example of it being used:
(the additional code in WndProc to handle WM_MOVING is necessary since the app cannot receive focus)
Imports System.Runtime.InteropServices
Public Class Form1
 
    Private Const WS_EX_NOACTIVATE = &H8000000
    Private Const WM_MOVING = &H216
 
    Private Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure
 
    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or WS_EX_NOACTIVATE
            Return cp
        End Get
    End Property
 
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_MOVING Then
            Dim r As RECT
            r = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(RECT)), RECT)
            Me.Location = New Point(r.Left, r.Top)
        End If
 
        MyBase.WndProc(m)
    End Sub
 
End Class

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You mean you've created an "onscreen keyboard"?  (see image below)

If so, you can use SendKeys.Send() to simulate the pressing of keys when your buttons are pushed:
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

osk.jpg
0
 
softspotAuthor Commented:
Thanks for this.Yes, it is a kind of on-screen keyboard but it does not resemble the regular keyboard at all.  I have created an application which allows limited-physical-ability users to have an alternative to the physical keyboard. When it runs, it  lets the user use a one-click action to select any key.I don't use the physical keys at all. The app cycles rapidly (and endlessly) through a series of nested loops, presenting' keys' to the user, and the user makes the selection.  I need the result of their selection, (i.e. the key-press) to act as input to whatever other application they are running (typically MS-Word etc). I have looked at SendKey.Send() but the problem is that it sends the key to the 'Active' application. This means that the keyboard application then becomes non-active. This may seem trivial but I don't see an easy solution. Also, there is the problem of finding the active application. The SetForeGroundWindow function is a possibility but I think this means  'going Native' which is not easy to manage. At least, I have never  worked outside of managed code  (in .NET) and so I don't have any experience at all in using native code.
I could give up and start over using C or Java but .NET made the development so far a real joy, and I am pushing our department to use .NET and I don't want to give up on this unless it really is not possible to find a solution.

Regards

Softspot

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
softspotAuthor Commented:
Firstly apologies for the delay in responding. I got called away to deal with other pressures. Thanks for your expert help with this problem. I have been able to use this essentially to create a solution and I have built a neat  little software 'control' app which enables me to provide the 'keyboard' input that was the initial obhjective, but which also has opened up a whole host of other possibilities. An issue which you probably know about, is that there can be a short but unpredictable delay in the transmission between the non-focused app and the currently live app. This is not a major issue for what I am doing now, but it could be for some apps, and a developer woulld need to take care with this. I speculate that it is simply XPs scheduler at work in which case there is probably not much that can be done. Anyway, that is an issue for further exploration. I learn a little more about .NET most every day and your advice and knowledge has been very much appreciated.
Regards
Softspot
0
 
softspotAuthor Commented:
Please see my comments. You have ramped my education up another notch. Much appreciated.

Softspot
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Another limitation to be aware of is that the WS_EX_NOACTIVATE flag will NOT work WITHIN the SAME application.  When used on a form in the same application it no longer prevents focus from being taken.  Thus the keyboard app has to be its own executable...
0
 
softspotAuthor Commented:
Thanks. That's useful to know.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.