英文:
How do I programmatically set "Display on-screen keyboard when no keyboard is connected?
问题
在Windows 11中,系统设置中有一个选项:“键盘” -> “如果未连接物理键盘,则显示虚拟键盘”。
我想知道如何通过API或任何其他编程方式打开/关闭此设置或获取其状态。
英文:
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.
答案1
得分: 1
有两种方法:
-
使用.NET API,请查看这个答案:https://stackoverflow.com/a/28472434/6894386
-
使用命令行工具和批处理脚本。
- 用于获取已连接键盘列表的命令(将 'hid' 更改为 'usb' 以获取物理 USB 连接的键盘,如果是鼠标,它还会显示任何 USB dongle)。
命令
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "Get-CimInstance win32_keyboard | Where Description -match 'hid' | Format-Table description, pnpDeviceID -AutoSize -Wrap"
输出
description pnpDeviceID HID Keyboard Device HID\{00001124-0000-1000-8000-00805F9B34FB}_VID&000204E8_PID&7021&COL01&2051871A&13&0000 HID Keyboard Device HID\CONVERTEDDEVICE&COL01&353EC129&0&0000
- 要启动屏幕键盘,请使用以下命令。
C:\WINDOWS\system32\osk.exe
通过组合这两个命令,您可以编写一个批处理文件,如果键盘不在列表中,则启动屏幕键盘,并将该文件添加到 %appdata%\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
这个文件夹中。
英文:
There are two methods
- Using .NET API check out this answer: https://stackoverflow.com/a/28472434/6894386
- 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.)
<br>Command<br>
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "Get-CimInstance win32_keyboard | Where Description -match 'hid' | Format-Table description, pnpDeviceID -AutoSize -Wrap"
<br>Output<br>
description pnpDeviceID
<br>
HID Keyboard Device HID\{00001124-0000-1000-8000-00805F9B34FB}_VID&000204E8_PID&7021&COL01\8&2051871A&13&0000
<br>
HID Keyboard Device HID\CONVERTEDDEVICE&COL01\5&353EC129&0&0000
- To start the on-screen keyboard, use the following command.<br>
C:\WINDOWS\system32\osk.exe
<br><br>
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论