Solved

vb.net call osk.exe position and size it & finally release it

Posted on 2010-08-30
5
4,129 Views
Last Modified: 2012-06-21
I have a win app in VB.net which needs an On Screen Keyboard for a short while from time to time. The Win 7 OSK.exe would work perfectly, if I can activate it, place it and size it. Hold it there for a while then stop it. A System.Diagnostic.Process control can do a big part of the job, however I could not figure out how to resize / place the OSK and hold it there until my app decides to reease it.
Win 7 Pro, Framework 3.5, VS2008.
Any subbestion?
Is there another KB in Win 7 (e.g. Tablet Mode related) which is easier to program control, or has an API?
0
Comment
Question by:jrscherer
  • 3
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 33568355
It would be something like this:

    Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" ( _
        ByVal handle As IntPtr, ByVal hWndInsertAfter As Integer, _
        ByVal x As Integer, ByVal y As Integer, _
        ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim app As String = "notepad" ' <-- doesn't work with "osk"

        Dim proc As Process = Nothing
        Dim ps() As Process = Process.GetProcessesByName(app)
        If ps.Length = 0 Then
            proc = Process.Start(app)
            proc.WaitForInputIdle()
        Else
            proc = ps(0)
        End If

        SetWindowPos(proc.MainWindowHandle, 0, 100, 100, 500, 500, 0)
    End Sub

***It works with notepad but OSK is a specialized window and it doesn't respond to the message...
0
 
LVL 9

Author Closing Comment

by:jrscherer
ID: 33600995
Hi Idle Mind. I have decided not to use the Win OSK after you confirmed that it does not behave like a regular Win program. Saved me a lot of trial and error time. Thx
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33601032
If you want to keep the "on-screen keyboard" as an EXTERNAL app (w/ respect to your "main" app") then you can roll your own OSK!...

Then you can size it and position it however you want:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21198438.html#12524392

*Just remember that your OSK has to be a separately running EXE...it will NOT work if displayed as just another Form in your app.
0
 
LVL 9

Author Comment

by:jrscherer
ID: 33601231
Thanks, Idle Mind. I have decided to write a small on-screen keyboard and use SendKey.Send to inject characters onto the WebBrowser Control on the same form (it is a touch screen app). With each button event I set the web browser to focus then send the char. So far so good.
But I run into another crazy problem: only every other button event creating a SendKey delivers the character to the WebBrowser Control. Control Characters like {Tab} work fine every time.
To check I have set up a textbox on the same form and feed every KeyPressed event e.KeyChar to the textbox. (KeyPreview is true in the form) Funny enough, every second button event delivers the character to the KeyPressed event, so the missing characters on the WebBrowser Control go to the KeyPressed Event. and no further. Kind of a flip-flop. Any idea?
 (Win 7, VS2008, FW3.5SP1)
BTW, Do ypou want me to open another question for points and public feedback?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33601276
"With each button event I set the web browser to focus then send the char."

If you study the code in my last link I use the WS_EX_NOACTIVATE flag which PREVENTS the "osk" from receiving focus:

    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

The side effect of this is that other apps NEVER LOSE focus when the "osk" is used by the user.  Thus with this approach you don't need to give focus back to the webbrowser since it never loses it in the first place.

This may fix the "flip-flop" issue...  =)
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question