• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 990
  • Last Modified:

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?
0
softspot
Asked:
softspot
  • 4
  • 3
1 Solution
 
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
 
Mike TomlinsonMiddle 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now