VBScript sendkeys, Trying to do CTRL+ALT+A

大兔子大兔子 提交于 2019-12-24 18:47:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!