Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-30
5
Medium Priority
?
4,513 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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

885 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