biker9
asked on
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_TERMIN ATE, 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
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_TERMIN
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
End Sub
Private Sub Worksheet_Deactivate()
Call closeOSK
End Sub
Why do you need to close the osk when your userform is open?
ASKER
The onscreen keyboard conflicts with a mini numeric key pad that the userform employs.
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.
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.
ASKER
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 .
Okay, here's a demo project.
Book1.xlsm
Book1.xlsm
ASKER
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.
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?
Can you attach your modified workbook?
ASKER
Here it is...
Book1-with-txtbox.xlsm
Book1-with-txtbox.xlsm
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)
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)
ASKER
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.
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.
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...
…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.
If neither of those work then I have no problem with you closing this thread without assigning any points.
Private Sub UserForm_Activate()
Kill_Process "On-Screen Keyboard" ' <-- change this
End Sub
…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
If neither of those work then I have no problem with you closing this thread without assigning any points.
ASKER
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?
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.
BTW I never did ask what you mean exactly when you say your mini-keyboard interferes with the 'keypad' in your userform.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thanks Marty, I appreciate your time on this.
You're welcome.