Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programatically opening the On Screen Keyboard 4

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
535
0
16
MU
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
 
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
 
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
 
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)
 
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
 
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".
 
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

 
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.
 
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.

Screenshot_2022-08-03_091409_y6jyhs.png
 
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.
 
Dear vernpace,

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
 
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
 
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.
 
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
 
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.
 
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
 
>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:
[COLOR=blue]#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

[COLOR=green]&& press Win + CTRL + o[/color]
keybd_event(VK_LWIN, 0, 0, 0)
keybd_event(VK_LCONTROL, 0, 0, 0)
keybd_event(VK_O, 0, 0, 0)

[COLOR=green]&& release Win + CTRL + o[/color]   
keybd_event(VK_O, 0, KEYEVENTF_KEYUP, 0)
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0)
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)[/color]
 
Strongm

Works a treat - thanks for that.

Now i just need to find a use for it

Colin
 
Dear strongm,

Amazing!

strongm said:
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




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top