问题
I'm testing Lexibar software for voice synthesis in our schoolboard. This kind of software is design to help students who have learning difficulty so I need to write a VBS file that simulate the Ctrl+Alt+A.
I tried :
- wshshell.sendkeys "^%{a}"
- "^%a"
- "^%{A}"
- "^%A"
- "^(%a)"
- "^(%(a))"
- ... (But nothing worked)
If I try wshshell.sendkeys "^%{down}" -> the screen rotate but I am not able to send Ctrl+Alt+A.
Is it blocked (Ctrl+Alt+Del is blocked).
回答1:
You should use it like ^%{a}
.
You may give focus to the application you want send keystrokes to by using AppActivate
method.
In your case, it should be like WshShell.AppActivate("MUST BE THE WINDOW YOU NEED TO SEND KEYSTROKES TO")
Find more about SendKeys
here.
回答2:
I now use powershell and it work great. With VBS, it worked once and then it stoped working. This is the code I run:
[void][reflection.assembly]::loadwithpartialname("system.windows.forms")
[system.windows.forms.sendkeys]::sendwait("^%a")
I used PS2EXE 0.5.1 to convert the script to a exe (SendKeys.exe), then I run it from this code:
Set wshShell = WScript.CreateObject("WScript.Shell")
wshShell.run "C:\Lexibar\SendKeys.exe",0
I need to run it from a vbs to avoid windows to pop. I used Vbs_To_exe to convert this one and now it work. (converting to .exe is just for security, hide my code from students)
回答3:
These are the commands I have used:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^%{a}"
You can use it with or without WshShell.AppActivate
, it is up to you.
This worked great for me.
来源:https://stackoverflow.com/questions/44332058/vbscript-sendkeys-trying-to-do-ctrlalta