返回列表 发帖

[问题求助] vbs 模拟发送按键,为什么会无效?

想模拟一下复制 “CTRL+C”,但是不知道为什么就无效。在xp系统下复制成功,但是到win7上面就没有用了!
希望好心的大侠,帮我看看!或者如何实现复制功能!谢谢了!

Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^C"

窗口失焦,要先聚焦到所要复制的某个窗口,比如要复制test.txt文档的某些文字,那么先选中文字
set ws = CreateObject("Wscript.Shell")
do while ws.appactivate("test.txt - 记事本")=false '聚焦到当前记事本窗口
WScript.Sleep 200
loop
ws.SendKeys "^C"COPY

TOP

本帖最后由 pcl_test 于 2015-8-18 19:00 编辑

发个ahk,实现鼠标左键拖选复制
~LButton::
mousedrag := 1 ; pixels
MouseGetPos, mousedrag_x1, mousedrag_y1
win1 := WinActive("A")
KeyWait LButton
MouseGetPos, mousedrag_x2, mousedrag_y2
win2 := WinActive("A")
WinGetClass cos_class, A
if(((abs(mousedrag_x2 - mousedrag_x1) > mousedrag
  or abs(mousedrag_y2 - mousedrag_y1) > mousedrag)) and win1 = win2
  and cos_class != "ConsoleWindowClass")
{
    SendInput ^c
}
returnCOPY

TOP

回复 2# pcl_test
这个不能任意地方 复制吧!我想实现的是,任意位置,比如:浏览器、qq、word …………等等;用vbs或者bat ,点击一下自动复制【自己设置一下快捷键,比如设置f4键,按下f4自动复制】。已选中的文字……

TOP

回复 4# ruoru376
嗯,说了vbs需要聚焦,一直是个不靠谱的方法,所以推荐用ahk

TOP

回复 5# pcl_test
没有用过ahk 不知道怎么用!应该如何运行呢!见笑了

TOP

回复 6# ruoru376

百度是让人“上”的

TOP

返回列表