Solved

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

Posted on 2010-08-30
5
4,021 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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 used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now