Эмулировать кнопку клавиатуры через командную строку

12741
Jaketr00

Моя клавиатура не имеет Num Lockключа, и по какой-то причине ни одно из изменений реестра не работает.

Можно ли использовать командную строку или PowerShell в Windows 10 для «нажатия» клавиши? Я ищу что-то вроде press pgupнажатия Page Upклавиши в командной строке или PowerShell, но для Num Lock.

10

2 ответа на вопрос

13
DavidPostill

How do I toggle numlock status using PowerShell.

Use the following script:

$wsh = New-Object -ComObject WScript.Shell $wsh.SendKeys('') 

Source StackOverflow answer PowerShell: Toggle “Num Lock” on and off. by Andy Arismendi

As pointed out by ABashore in his comment this can be shortened as follows:

$wshell.SendKeys('') 
Похоже, вам не нужно определять «wsh», чтобы делать то, что ему нужно. Я смог просто переключить NUMLOCK одной строкой. ABashore 8 лет назад 0
@ABashore Круто. Я проголосовал за ваш ответ DavidPostill 8 лет назад 0
9
ABashore

Here's a powershell line that will toggle your NUMLOCK. I've tested this and it works on my Logitech K120 USB keyboard.

$wshell.SendKeys('') 

Here's a list of the other SendKey codes.

If you need to send the keystroke to an interactive application, more code will be needed.