• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 958
  • Last Modified:

Excel userforms and disabling the Microsoft office 2010 on-screen keyboard

Hello Experts,


I have a pc tablet computer (Windows 7), and would like to disable the on-screen upon opening an Excel userform. I have found the following code by "kukush" on the excel forum site that dates back to 2008 that opens & closes the Office onscreen keyboard when opening/closing a worksheet. I don’t know whether it will work with 2010 Office, way beyond my limited vba.

Can an expert modify this code (or offer an alternative idea) to close the on-screen keyboard when opening a specifc userform, and then return the on-screen keyboard to it’s normal functioning upon closing the userform.

Thanks,
Ray



Option Explicit

Private Declare Function CloseHandle Lib "kernel32" ( _
  ByVal hObject As Long) As Long
 
Private Declare Function OpenProcess Lib "kernel32" ( _
  ByVal dwDesiredAccess As Long, _
  ByVal bInheritHandle As Long, _
  ByVal dwProcessId As Long) As Long
 
 
Private Declare Function TerminateProcess Lib "kernel32" ( _
  ByVal hProcess As Long, _
  ByVal uExitCode As Long) As Long
 
Const PROCESS_TERMINATE = &H1


' TaskID of running osk.exe
Public lTaskID As Long


Public Sub closeOSK()
  Dim lhwnd As Long
  Dim lResult As Long
 
  lhwnd = OpenProcess(PROCESS_TERMINATE, 0&, lTaskID)
  lResult = TerminateProcess(lhwnd, 1&)
  lResult = CloseHandle(lhwnd)
End Sub


Private Sub Worksheet_Activate()
' returns TaskID of running osk.exe to public variable lTaskID
lTaskID = Shell("C:\WINDOWS\system32\osk.exe", 1)
End Sub

Private Sub Worksheet_Deactivate()
Call closeOSK
End Sub
0
biker9
Asked:
biker9
  • 10
  • 8
1 Solution
 
Martin LissRetired ProgrammerCommented:
Why do you need to close the osk when your userform is open?
0
 
biker9Author Commented:
The onscreen keyboard conflicts with a mini numeric key pad that the userform employs.
0
 
Martin LissRetired ProgrammerCommented:
The osk is not something that everyone knows about and in any case why can't you tell your users not to use it while userform is open?

BTW, showing the osk when the userform starts and closing it when the userform closes is easy. The opposite is harder since you have to find the process handle.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
biker9Author Commented:
When using a pen device on the tablet and triggering the userform, the osk hovers over the userform, so its an annoyance and confusing to the user, so preferably it shouldn't be there. I know zip about process handles, but the code I found from the other site seems to refer to it .
0
 
Martin LissRetired ProgrammerCommented:
Okay, here's a demo project.
Book1.xlsm
0
 
biker9Author Commented:
Sorry for the delay in responding.  I added a text box to the demo project form to test this out, and discovered the osk will display when a pen hovers over the box in spite of the code.
0
 
Martin LissRetired ProgrammerCommented:
I don't see how that's possible since when the button is clicked on the sheet to display the userform, it checks to see if osk is running and if it is then osk is killed and not merely hidden.

Can you attach your modified workbook?
0
 
biker9Author Commented:
Here it is...
Book1-with-txtbox.xlsm
0
 
Martin LissRetired ProgrammerCommented:
It works fine for me on my PC. Here's what I did:


1.    Open the workbook
2.    Start osk via Start|run|osk
3.    Click CommandButton1  (osk disappears)
4.    Run cursor over textbox  (osk does not appear)
5.    Close userform via the 'X' (osk appears again)
0
 
biker9Author Commented:
I followed your instructions and tested on my pc, and the osk won't go away, I have two monitors set up, maybe that's the problem with the pc?

But I more concerned about the osk going away on my tablet pc (Asus ep121) and no luck with that either, perhaps something specific to the osk on the Asus is going on? A mini keyboard icon appears (mini as in about 1 inch in length) next to the textbox in spite of the code.
0
 
Martin LissRetired ProgrammerCommented:
Okay I can't do much more here because I have neither two monitors nor a laptop like yours. The only suggestion I can make is that if there's a title on the "mini keyboard" then in the spreadsheet change the UserForm_Activate code to match the title...

Private Sub UserForm_Activate()
Kill_Process "On-Screen Keyboard" ' <-- change this

End Sub

Open in new window


…and if the mini-keyboard is a stand-alone exe (like osk is) then change the Shell statement to match your path to that stand-alone exe.

Private Sub UserForm_Terminate()
If gbOSKFound Then
    lTaskID = Shell("C:\WINDOWS\system32\osk.exe", 1)
    gbOSKFound = False
End If

End Sub

Open in new window


If neither of those work then I have no problem with you closing this thread without assigning any points.
0
 
biker9Author Commented:
It seems that the tablet osk is referred to as the "Tablet PC Input Panel" and I think the exe is referred to as the tabtip.exe. I can't find the equivalent Kill_Process "On-Screen Keyboard" as it would apply to the Tablet PC Input Panel, any guesses?
0
 
Martin LissRetired ProgrammerCommented:
If you go to Start|Run and then enter osk in the 'Open' dialog and press enter, the osk will appear as in the attached picture and you'll see that it is titled "On-Screen Keyboard". Does your mini keyboard have a title like that? If it does you should be able to close it by changing the text to that title (see post ID: 38309743).

BTW I never did ask what you mean exactly when you say your mini-keyboard interferes with the 'keypad' in your userform.
0
 
Martin LissRetired ProgrammerCommented:
I forgot the picture.

osk
0
 
biker9Author Commented:
Nope, no title that I can see similar to the one in your picture, you can enable it the tablet keyboard on your pc by typing at Start "Tablet PC Input Panel", when you "X" to exit, it should hide itself on the top left side of your monitor, you renable it by clicking on its frame, and disable it completely by clicking (on the tablet pc onscreen keyboard) Tools/Exit. So I would have thought that it could be replicated in VBA.

as far as interference is concerned, I probably should have used the word "annoyance", since its more of an annoyance and confusion to to the user than anything when both a custom keyboard and the tablet pc input keyboard are available, so I would prefer it not to be there.
0
 
Martin LissRetired ProgrammerCommented:
There are articles on the web like this one that talks about disabling it.
0
 
biker9Author Commented:
ok thanks Marty, I appreciate your time on this.
0
 
Martin LissRetired ProgrammerCommented:
You're welcome.
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.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now