0

In Windows 11, there is the option "Keyboard" -> "Show virtual keyboard if not physical keyboard is attached" in the system settings.

I would like to know how I could turn this setting on / top or get its status using an API or any other programmatic way.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tmighty
  • 10,734
  • 21
  • 104
  • 218

1 Answers1

1

There are two methods

  1. Using .NET API check out this answer: https://stackoverflow.com/a/28472434/6894386

  1. Using command-line tools and batch script.
  • Command to get a list of keyboards connected (change 'hid' to 'usb' for physical USB connected). (It will also show any USB dongle if it's a mouse.)


Command
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "Get-CimInstance win32_keyboard | Where Description -match 'hid' | Format-Table description, pnpDeviceID -AutoSize -Wrap"
Output
description pnpDeviceID
HID Keyboard Device HID\{00001124-0000-1000-8000-00805F9B34FB}_VID&000204E8_PID&7021&COL01\8&2051871A&13&0000
HID Keyboard Device HID\CONVERTEDDEVICE&COL01\5&353EC129&0&0000

  • To start the on-screen keyboard, use the following command.
    C:\WINDOWS\system32\osk.exe

    Combining these two commands, you can write a batch file to start OSK if the keyboard is not present in the list. And add that file to %appdata%\Roaming\Microsoft\Windows\Start Menu\Programs\Startup this folder
8-DK
  • 191
  • 1
  • 5