×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Programatically opening the On Screen Keyboard
4

Programatically opening the On Screen Keyboard

Programatically opening the On Screen Keyboard

(OP)
Hi,

Anyone has an idea how we can open the Windows OSK (On Screen Keyboard, osk.exe) programatically?
In fact, for example, I want to invoke OSK upon clicking a button.

Thanks

RE: Programatically opening the On Screen Keyboard

I'm not familiar with the on-screen keyboard. But, given that it is an executable, can you not do it with ShellExecute:

CODE -->

DECLARE INTEGER ShellExecute IN shell32.dll ; 
  INTEGER hndWin, ; 
  STRING cAction, ; 
  STRING cFileName, ; 
  STRING cParams, ;  
  STRING cDir, ; 
  INTEGER nShowWin

cFileName = "osk.exe"  && add full path here if necessary
cAction = "open" 
ShellExecute(0,cAction,cFileName,"","",1) 

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Programatically opening the On Screen Keyboard

with a few minutes to spare i thought that i would try Mike's suggestion

and ....

it doesn't work

a quick google shows that other people have issues launching OSK - even from .net applications ( but i have yet to try that )

this will be an interesting one to get functional

RE: Programatically opening the On Screen Keyboard

DECLARE INTEGER Wow64EnableWow64FsRedirection IN kernel32.dll;
INTEGER nEnable

DECLARE INTEGER ShellExecute IN shell32.dll;
INTEGER nWinHandle, STRING cOperation, STRING cFileName, STRING cParameters, STRING cDirectory, INTEGER nShowWindow

Wow64EnableWow64FsRedirection(0)
ShellExecute(0, "open", "OSK.exe", "", "", 0)
Wow64EnableWow64FsRedirection(1)

RE: Programatically opening the On Screen Keyboard

Colin and Vernspace: It looks like you are both right.

My code worked OK, in that it correctly created a window handle for the keyboard, but the keyboard itself was not visible.

Vernspace's code worked perfectly. I wish I understod why.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Programatically opening the On Screen Keyboard

Mike,

It has to do with passing 0 instead of 1 for the nShowWindow parameter. While this is counter-intuitive, it is necessary I think because of it's use with Wow64EnableWow64FsRedirection. Zero for nShowWindow is defined by Microsoft: "SW_HIDE 0 - Hides the window and activates another window".

RE: Programatically opening the On Screen Keyboard

That makes sense, Vernspace. Thanks for the explanation.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Programatically opening the On Screen Keyboard

(OP)
Dear vernspace,
Thank you for the code.

I thought it worked once.
But, after that, the Osk is not popping up even through Run command.
Just for checking, I tried with both 0 & 1 for nShowWindow parameter, but without luck.

But, Mike has confirmed it worked perfectly.
I am trying to figure out what's going wrong at my end!

Any clue?

Rajesh

RE: Programatically opening the On Screen Keyboard

I don't know how you are implementing this. You need to have focus on the object (e.g. TextBox) you want to receive the output from the On-Screen Keyboard. I think invoking with a button click is problematic. You may want to create a procedure:

CODE -->

PROCEDURE ShowOnScreenKeyBoard() AS VOID
   DECLARE INTEGER Wow64EnableWow64FsRedirection IN kernel32.dll;
   INTEGER nEnable

   DECLARE INTEGER ShellExecute IN shell32.dll;
   INTEGER nWinHandle, STRING cOperation, STRING cFileName, STRING cParameters, STRING cDirectory, INTEGER nShowWindow

   Wow64EnableWow64FsRedirection(0)
   ShellExecute(0, "open", "OSK.exe", "", "", 0)
   Wow64EnableWow64FsRedirection(1)

ENDPROC 

Then call ShowOnScreenKeyBoard() from the GotFocus() Event of the TextBox control. That way, the TextBox will have focus to receive the output from the On-Screen Keyboard.

RE: Programatically opening the On Screen Keyboard

(OP)
Hi vernspace,

Yes, of course, I understand that. But my idea was to give user choice of invoking the keyboard only if required, both for alphanumeric and as a num pad.

I tried your code. I have a form, with textboxes and grid. But, it gives me an alert/message box (attached image). My OS is Win 10 64bit. Wondering what I am missing or the OSK is highly dependent on the OS configuration/environment.

Thanks.

RE: Programatically opening the On Screen Keyboard

Rajesh,

I just now tested on Windows 10 (latest build) and you are correct - it doesn't work. After a bit of research, it appears that MS has changed everything with respect to the OSK. Sorry, I had no idea. There doesn't appear to be a clear cut solution.

RE: Programatically opening the On Screen Keyboard

(OP)
Dear vernpace,

No need to say 'Sorry' here. Could you please take it back smile ?
It hurts more than the fact that the osk didn't work for us.

Let's look forward if something comes up soon!
If I get some clue, that will be here for sure.

Thanks a lot
Rajesh

RE: Programatically opening the On Screen Keyboard

I too was going to say that it doesn't work for me either on Win10 (latest).

so as I said, an interesting one to resolve, even more interesting if it can't be

Colin

RE: Programatically opening the On Screen Keyboard

An alternative that works reliably (or at least seems to) in VB6/VBA is to directly use the SendInput API call to replicate Windows Key + CTRL + o, which is the keyboard shortcut to display the OSK.

RE: Programatically opening the On Screen Keyboard

(OP)
Hi friends,

I need to say bye bye to Windows OSK it seems!

So, can anyone suggest any good On Screen Keyboard as OCX or DLL (free or paid) that can be plugged into VFP application?

For time being, I have built my own numpad and it works okay. Had to tweak my form a bit.

Rajesh

RE: Programatically opening the On Screen Keyboard

To all,

In our applications, 64-bit redirection is being suspended by a pair of Wow64DisableWow64FsRedirection and Wow64RevertWow64FsRedirection calls (as suggested by Microsoft). The execution of an external program is tried, at first, by instantiating a Shell.Application object, and only if it fails, by a call to ShellExecute API function.

That said, OSK can be launched this way even in Windows 11, as far as our experience goes.

RE: Programatically opening the On Screen Keyboard

Quote:

For time being, I have built my own numpad and it works okay

Rajesh, I was going to ask you if you had considered building your own keyboard? I imagine it might be difficult to get it to look nice. Then again, the Microsoft version isn't all that aesthetically pleasing, in my opinion.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Programatically opening the On Screen Keyboard

2
>I need to say bye bye to Windows OSK it seems!

Don't give up quite yet! Below is my attempt at implementing my earlier suggestion of using SendInput. A quick investigation showed that it might be a pain to implement in FoxPro because it uses structures, so I simply switched for the alternative, simpler keybd_event API call. I'm not a FoxPro programmer, and I put this together in Notepad, but I *think* the code is correct.

CODE -->

#DEFINE KEYEVENTF_KEYUP 0x2
#DEFINE VK_LCONTROL 0xA2
#DEFINE VK_LWIN 0x5B
#DEFINE VK_O 0x4F

DECLARE keybd_event IN user32;
    SHORT bVk,;
    SHORT bScan,;
    INTEGER dwFlags,;
    INTEGER dwExtraInfo

&& press Win + CTRL + o
keybd_event(VK_LWIN, 0, 0, 0)
keybd_event(VK_LCONTROL, 0, 0, 0)
keybd_event(VK_O, 0, 0, 0)

&& release Win + CTRL + o   
keybd_event(VK_O, 0, KEYEVENTF_KEYUP, 0)
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0)
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0) 

RE: Programatically opening the On Screen Keyboard

Strongm

Works a treat - thanks for that.

Now i just need to find a use for it

Colin

RE: Programatically opening the On Screen Keyboard

(OP)
Dear strongm,

Amazing!

Quote (strongm)

Don't give up quite yet!
Thank you very much for that1

Now, let me put this into a PROCEDURE and call it from my form and check it.
Whether it works that way or not, you really deserve Stars for this code!

Will update here soon.

Rajesh




RE: Programatically opening the On Screen Keyboard

(OP)
Mike,

Quote (Mike)

Rajesh, I was going to ask you if you had considered building your own keyboard?

Yes, for time being only a Num pad, not full keyboard. Anyway, I was not building a generalized keyboard but only wanted to have for current form I am working on. I made a container with numeric keys turning its Visible on/off as required and it works for my purpose.

Rajesh


RE: Programatically opening the On Screen Keyboard

(OP)
strongm,

It invokes the OSK upon click of a button. Works fine!

My need is actually for a form which is supposed to work on a touch screen where there is no keyboard/mouse.
So, now my problem is, how do I close the OSK programmatically, once the user confirms (by touching Enter) what he was typing?

In my current form, where I have my own Num pad, I take off the Num Pad, once user touch Enter and in that case, many of my Textboxes will run its 'VALID'/'LOSTFOCUS' etc as the case maybe, processing it further.

But, with our Windows OSK, all these controls are not in my hands, I suppose!

However, dear strongm,
I have many other ideas coming up in my mind (not for OSK though).
Thank you very much for triggering that... smile

Rajesh

RE: Programatically opening the On Screen Keyboard

>So, now my problem is, how do I close the OSK programmatically

Just run the code I provided a second time ...

RE: Programatically opening the On Screen Keyboard

(OP)
strongm,

Oh..... was it that simple?!
I didn't think that way.
Now, let me check if all these can be turned to match my requirements.

Thank you dear
Rajesh

RE: Programatically opening the On Screen Keyboard

(OP)
Dear strongm / Dear others,

It seems fantastic now!
I can activate/deactivate OSK from a button on the form.

Now, I want to check if OSK is already activated or not.
I tried WEXISTS(), WONTOP() etc with the Title "On-Screen Keyboard" that OSK shows.
But, that's not the name we have to refer, it seems!

Any idea?
To go through Windows Processes is one way? Let me check it.

Rajesh

RE: Programatically opening the On Screen Keyboard

(OP)
Hi All,

I managed to determine if on screen keyboard is running or not by checking OSK.EXE in Win32_Process

Thanks
Rajesh

RE: Programatically opening the On Screen Keyboard

Good to see you got it working, Rajesh. And kudos to Strongm. I would never have come up with that solution myself.

Mie

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Programatically opening the On Screen Keyboard

I thought another approach for Win10 could be to KEYBOARD Win+Ctrl+o, which would pop up the OSK. But apparently VFP has no code for the Win key (that I could find, anyway). Srongm's code is a great workaround though!

Steve

RE: Programatically opening the On Screen Keyboard

>I tried WEXISTS(), WONTOP() etc with the Title "On-Screen Keyboard" that OSK shows.

Try something like the following

CODE -->

DECLARE INTEGER FindWindowEx IN user32;
	INTEGER  hwndParent,;
	INTEGER  hwndChildAfter,;
	STRING @ lpszClass,;
	STRING @ lpszWindow

OSKRunning = FindWindowEx(0, 0, "OSKMainClass", "On-Screen Keyboard") <> 0 

RE: Programatically opening the On Screen Keyboard

(OP)
Steve,

strongm's code is actually doing exactly the same thing!

Rajesh

RE: Programatically opening the On Screen Keyboard

(OP)
Strongm,

I have already managed to determine if the On screen keyboard is running or not by checking OSK.EXE in Win32_Process.
It's working.

Anyway, I will make your code as a procedure and try to use it.
Thank you.

Rajesh

RE: Programatically opening the On Screen Keyboard

Win32_process normally indicated the use of WMI and, whilst very useful, WMI quite slow. So just thought I'd offer a faster alternative more in keeping with you own easier efforts (I.e. looking for the window)

RE: Programatically opening the On Screen Keyboard

(OP)
strongm / other friends,

The OSK toggle code which works in Win 10 doesn't seem to work in Windows Server 2016 Datacenter.
I mean, it's the Shortcut key combination that doesn't work. If I Run osk.exe, it opens up.

Too, Mike's code with ShellExecute and your subsequent suggestion of same with 'Wow64EnableWow64FsRedirection',
both did not work.

Are these problems because of a security concern in Win Server 2016?

Any idea?

Rajesh

RE: Programatically opening the On Screen Keyboard

If you physically press win + ctrl + o. Does it work? You may need to enable OSK on 2016 data center in settings

RE: Programatically opening the On Screen Keyboard

Quote (strongm)

If you physically press win + ctrl + o.

strongm,

It works on my Win10 machine. One time it didn't. Can't recall what I did. Reliability?

Also it worked when I clicked on osk.exe in C:\Windows\System32\. But I couldn't make it work using the RUN command. Don't know why.

In any case, it seems your code is the best solution. Thanks for that!

Steve

RE: Programatically opening the On Screen Keyboard

(OP)
strongm,

Quote (strongm)

So just thought I'd offer a faster alternative more in keeping with you own easier efforts (I.e. looking for the window)
Yes, I will check this also for sure. As you know, my purpose was to determine if the OSK is already open as I want to show it when focus comes to Textbox, Combo, Grid etc where user input is acceptable, which is further based on a configuration setting if the OSK needs to be shown automatically or not.

Quote (strongm)

If you physically press win + ctrl + o. Does it work?
I can see that On Screen Keyboard is 'ON' in Windows 2016 Data Centre server under
Settings -> Ease Of Access -> Keyboard. However, if I physically press win + ctrl + o, nothing happens!
Could be a restriction by design because its a 'Server' and not a normal Win 10 pc.
Let me check further.

Thank you
Rajesh

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close