Trigger Windows 10 On-screen Keyboard using VBA (1 Viewer)

jmaty23

Registered User.
Local time
Today, 13:54
Joined
Jul 24, 2012
Messages
53
My apologies if this question has already been asked and if so, I cannot seem to find it.

I am working on building a front-end Access database that will be running on a Windows 10 Tablet.

What I would like to be able to do is trigger the tablet on-screen keyboard that shows up when you click the keyboard icon that resides in the lower right hand corner of the screen. (To the left of the clock.)

I've include 2 images as attachments. One images shows the keyboard button that i'm talking about and the other shows the actual keyboard that i'm trying to show/hide on the screen using VBA.

If anyone could point me to an API or function that they have been able to get to work, i'd appreciate it.
 

Attachments

  • _2.IMG_20161122_075440.jpg
    _2.IMG_20161122_075440.jpg
    37.8 KB · Views: 715
  • 6751.jpg
    6751.jpg
    42.2 KB · Views: 701

Tieval

Still Clueless
Local time
Today, 17:54
Joined
Jun 26, 2015
Messages
475
I believe UncleGizmo did a tutorial on this and am sure he will be along to point you in the right direction
 

jmaty23

Registered User.
Local time
Today, 13:54
Joined
Jul 24, 2012
Messages
53
I was able to create this subroutine to make the keyboard show. Thanks for the post!

Sub Keyboard()
On Error GoTo ErrorHandler

Call ShellEx("C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe")

ProcedureExit:
Exit Sub

ErrorHandler:
MsgBox "Error" & ": " & Err.Number & vbCrLf & "Description: " _
& Err.Description, vbExclamation, "Module1.Keyboard"
Resume ProcedureExit

End Sub
 

fatkarl

New member
Local time
Today, 12:54
Joined
Mar 9, 2017
Messages
1
Thanks Jmaty,

Do you mind posting what you have for ShellEx? I'm not having luck with the versions of ShellExecute I've found...
 
Local time
Today, 23:24
Joined
Feb 5, 2020
Messages
2
this worked fine for us on Win 10 MS access 2013

it is available throughout the project. Hopefully it will help others



Dim lngPtr As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

'Call Wow64DisableWow64FsRedirection prior to calling ShellExecute and Wow64RevertWow64FsRedirection, immediately after.
Private Declare Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" (ByRef ptr As Long) As Boolean
Private Declare Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" (ByRef ptr As Long) As Boolean
Public Function ShowKeyboard()
Call Wow64DisableWow64FsRedirection(lngPtr)
ShellExecute 0, "open", "osk.exe", "", "", vbNormalFocus
Call Wow64RevertWow64FsRedirection(lngPtr)
End Function

Public Function HideKeyboard()
Call Wow64DisableWow64FsRedirection(lngPtr)
ShellExecute 0, "open", "tskill", "osk", "", vbHidden
Call Wow64RevertWow64FsRedirection(lngPtr)
End Function
 

isladogs

MVP / VIP
Local time
Today, 17:54
Joined
Jan 14, 2017
Messages
18,186
Hi 'Access Database Developer' and welcome to the forum
I'm amazed that username was available. Surprising its never been used before in the past 20 years of AWF

=============================================================

Anyway, to show yet again that there are several ways of doing the same thing...
I posted the attached DEMO a couple of years ago but have been unable to find the thread with the new search facility:

Capture.PNG

The DEMO app allows you to use either of the two different on-screen keyboards that can be used:
1. osk.exe - the old accessibility keyboard
2. tabtip.exe - the newer keyboard designed for tablets but available on any workstation

The code I use is similar to that in post #4
This code is used in a standard module and works in both 32-bit and 64-bit:

SQL:
Option Compare Database
Option Explicit

'###############################################
#If VBA7 Then 'use PtrSafe & LongPtr
    Private Declare PtrSafe Function apiShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hWnd As LongPtr, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) _
        As Long
#Else
    Private Declare Function apiShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hWnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) _
        As Long
#End If
'###############################################

Public strApp As String

Public Function RunOSK()

'opens on screen keyboard if opened in tablet mode
'To test it on a standard PC, disable the 'If ...End If
'If modMetrics.System(SM_TABLETPC) Then
    apiShellExecute 0, vbNullString, "osk.exe", vbNullString, "C:\", 1
'   ShellEx "c:\windows\system32\osk.exe", , True
   strApp = "osk.exe"
'End If

End Function
Public Sub ShellEx(ByVal Path As String, Optional ByVal Parameters As String, Optional ByVal HideWindow As Boolean)

    If Dir(Path) > "" Then
        apiShellExecute 0, "open", Path, Parameters, "", IIf(HideWindow, 0, 1)
    Else
        MsgBox "Can't find application"
    End If

End Sub

Public Function OpenTabTip()

'opens tablet screen keyboard in tablet mode
'To test it on a standard PC, disable the 'If ...End If
'If modMetrics.System(SM_TABLETPC) Then
    ShellEx "C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe", , True
    strApp = "TabTip.exe"
'End If

End Function

Then in the form you just need to use either RunOSK or OpenTabTip on a button click or Form_Load event.
I have done that but in a slightly different way in the attached
 

Attachments

  • OnScreenKeyboardDEMO.zip
    45.2 KB · Views: 579

wichan.k

New member
Local time
Tomorrow, 00:54
Joined
Mar 17, 2020
Messages
3
Hi 'Access Database Developer' and welcome to the forum
I'm amazed that username was available. Surprising its never been used before in the past 20 years of AWF

=============================================================

Anyway, to show yet again that there are several ways of doing the same thing...
I posted the attached DEMO a couple of years ago but have been unable to find the thread with the new search facility:

View attachment 78867

The DEMO app allows you to use either of the two different on-screen keyboards that can be used:
1. osk.exe - the old accessibility keyboard
2. tabtip.exe - the newer keyboard designed for tablets but available on any workstation

The code I use is similar to that in post #4
This code is used in a standard module and works in both 32-bit and 64-bit:

SQL:
Option Compare Database
Option Explicit

'###############################################
#If VBA7 Then 'use PtrSafe & LongPtr
    Private Declare PtrSafe Function apiShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hWnd As LongPtr, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) _
        As Long
#Else
    Private Declare Function apiShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hWnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) _
        As Long
#End If
'###############################################

Public strApp As String

Public Function RunOSK()

'opens on screen keyboard if opened in tablet mode
'To test it on a standard PC, disable the 'If ...End If
'If modMetrics.System(SM_TABLETPC) Then
    apiShellExecute 0, vbNullString, "osk.exe", vbNullString, "C:\", 1
'   ShellEx "c:\windows\system32\osk.exe", , True
   strApp = "osk.exe"
'End If

End Function
Public Sub ShellEx(ByVal Path As String, Optional ByVal Parameters As String, Optional ByVal HideWindow As Boolean)

    If Dir(Path) > "" Then
        apiShellExecute 0, "open", Path, Parameters, "", IIf(HideWindow, 0, 1)
    Else
        MsgBox "Can't find application"
    End If

End Sub

Public Function OpenTabTip()

'opens tablet screen keyboard in tablet mode
'To test it on a standard PC, disable the 'If ...End If
'If modMetrics.System(SM_TABLETPC) Then
    ShellEx "C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe", , True
    strApp = "TabTip.exe"
'End If

End Function

Then in the form you just need to use either RunOSK or OpenTabTip on a button click or Form_Load event.
I have done that but in a slightly different way in the attached
 

wichan.k

New member
Local time
Tomorrow, 00:54
Joined
Mar 17, 2020
Messages
3
Thank you for the code. But may I has a question.
Code ”me.lblinto” What has been your mean in this code? When I run code error
 

isladogs

MVP / VIP
Local time
Today, 17:54
Joined
Jan 14, 2017
Messages
18,186
Hi @wichan.k
Not sure who you are asking. Where is that code line and what error did you get?
 

wichan.k

New member
Local time
Tomorrow, 00:54
Joined
Mar 17, 2020
Messages
3
Hi @ isladogs

Private Sub CheckOSKStatus()

Select Case Me.OpenArgs

Case "OSK"
RunOSK
Me.lblInfo.Caption = "Running on screen keyboard 'osk.exe'"
Case "TabTip"
OpenTabTip
Me.lblInfo.Caption = "Running tablet keyboard 'TabTip.exe'"
Case Else
Me.lblInfo.Caption = "No on screen keyboard in use"
End Select


End Sub

When I run debug Program alert "method or data member not found"
 

isladogs

MVP / VIP
Local time
Today, 17:54
Joined
Jan 14, 2017
Messages
18,186
In Form2 of my demo, lblInfo is a label whose caption depends on which on screen keyboard is in use (if any).
The label caption is just for info and can be omitted if not required
You should either add a label with that name to your form or just delete the lblInfo.Caption lines from the code
 

Users who are viewing this thread

Top Bottom