Solved

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

Posted on 2010-08-30
5
4,284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

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 86

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 86

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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