Solved

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

Posted on 2010-08-30
5
3,952 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

10 Experts available now in Live!

Get 1:1 Help Now