WshShell按键多媒体Next Track窗口

时间:2015-02-04 04:00:22

标签: testing keyboard-events keystroke wsh

我有一个wscript,它会向活动窗口发送一个按键。

我有以下媒体键的按键代码:

Vol +(代码:& hAF)

Vol - (代码:& hAE)

Prev Track(代码:& hB1)

下一曲目(代码:& hB0)(不工作)

播放/暂停(代码:& hB3)

但我无法使其模拟Next Track键,我认为它与十六进制代码中的0相关

这是发送按键的代码:

'this script is working on W7 and W8    
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hB0)) 'change the chr argument by any hex to send keystrokes to the active window
Set WshShell = Nothing

我以此链接为基础来获取代码:http://orlando.mvps.org/SendKeysMore.asp

问题是,不是发送按键“Media Next”,而是向活动窗口发送按键“°”

转换为十进制的十六进制(& hB0)为176,176映射为°

非常感谢帮助。

提前致谢

1 个答案:

答案 0 :(得分:3)

我解决了我的问题。出于某种原因,我无法使上述代码正常工作。

使用其他方法(和谷歌)我找到了一个C脚本

位于此处: https://batchloaf.wordpress.com/2012/04/17/simulating-a-keystroke-in-win32-c-or-c-using-sendinput/

测试之后,我修改了代码以传递参数: 发布在这里: https://batchloaf.wordpress.com/2012/04/17/simulating-a-keystroke-in-win32-c-or-c-using-sendinput/#comment-4808

参数(关键代码)取自: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx

我使用Cygwin编译代码,所以如果你想在另一台机器上运行已编译的代码,你需要在类路径上安装cygwin1.dll。