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
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
CODE -->
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Programatically opening the On Screen Keyboard
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
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
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
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
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Programatically opening the On Screen Keyboard
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
CODE -->
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
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
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
No need to say 'Sorry' here. Could you please take it back
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
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
RE: Programatically opening the On Screen Keyboard
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
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
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
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
Works a treat - thanks for that.
Now i just need to find a use for it
Colin
RE: Programatically opening the On Screen Keyboard
Amazing!
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
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
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...
Rajesh
RE: Programatically opening the On Screen Keyboard
Just run the code I provided a second time ...
RE: Programatically opening the On Screen Keyboard
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
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
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
Mie
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Programatically opening the On Screen Keyboard
Steve
RE: Programatically opening the On Screen Keyboard
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
strongm's code is actually doing exactly the same thing!
Rajesh
RE: Programatically opening the On Screen Keyboard
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
RE: Programatically opening the On Screen Keyboard
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
RE: Programatically opening the On Screen Keyboard
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
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.
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