Autohotkey 当ControlSend或Send不';不行?

Autohotkey 当ControlSend或Send不';不行?,autohotkey,Autohotkey,我最近升级到Windows 8.1 x64,现在我使用的脚本不再工作了。该脚本将右键单击某个程序的托盘图标,然后导航到其中一个选项,然后单击该选项 下面是脚本::: ;#NoTrayIcon DetectHiddenWindows, On ;Outlook on the Desktop----------------------------------------------------------------------------------------------------------

我最近升级到Windows 8.1 x64,现在我使用的脚本不再工作了。该脚本将右键单击某个程序的托盘图标,然后导航到其中一个选项,然后单击该选项

下面是脚本:::

;#NoTrayIcon
DetectHiddenWindows, On

;Outlook on the Desktop--------------------------------------------------------------------------------------------------------------------------------

^1:: ;25,000$ Fine Tuned

Info := TrayIcons("OutlookDesktop.exe") ; OutlookDesktop.exe is the prog i tested with
StringSplit, TrayInfo, Info,|
PostMessage, TrayInfo1, TrayInfo2, 0x0205,, ahk_id %TrayInfo3% ; this is the right-click
Sleep 500
Send {Down 3}{Right}{Down 7}{Right}{Down 4}{Enter}
return

^2:: ;Projects

Info := TrayIcons("OutlookDesktop.exe") ; OutlookDesktop.exe is the prog i tested with
StringSplit, TrayInfo, Info,|
PostMessage, TrayInfo1, TrayInfo2, 0x0205,, ahk_id %TrayInfo3% ; this is the right-click
Sleep 500
Send {Down 3}{Right}{Down 7}{Right}{Down 1 4}{Enter}
return

^3:: ;Due This Week - unfinished

Info := TrayIcons("OutlookDesktop.exe") ; OutlookDesktop.exe is the prog i tested with
StringSplit, TrayInfo, Info,|
PostMessage, TrayInfo1, TrayInfo2, 0x0205,, ahk_id %TrayInfo3% ; this is the right-click
Sleep 500
Send {Down 3}{Right}{Down 7}{Right}{Down 2 4}{Enter}
return

^4:: ;To-do Bar Calendar View

Info := TrayIcons("OutlookDesktop.exe") ; OutlookDesktop.exe is the prog i tested with
StringSplit, TrayInfo, Info,|
PostMessage, TrayInfo1, TrayInfo2, 0x0205,, ahk_id %TrayInfo3% ; this is the right-click
Sleep 500
Send {Down 3}{Right}{Down 7}{Right}{Down 7 4}{Enter}
return

; Found and abused from
; http://www.autohotkey.com/forum/topic17314.html
; thx, Sean ... GREAT WORK!

TrayIcons(sExeName = "OutlookDesktop.exe")
{
WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
pRB := DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0
, "Uint", 20, "Uint", 0x1000, "Uint", 0x4)
VarSetCapacity(btn, 20)
VarSetCapacity(nfo, 24)
VarSetCapacity(sTooltip, 128)
VarSetCapacity(wTooltip, 128 * 2)
SendMessage, 0x418, 0, 0, ToolbarWindow32, ahk_class Shell_TrayWnd
Loop, %ErrorLevel%
{
SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32, ahk_class Shell_TrayWnd
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pRB, "Uint", &btn, "Uint", 20, "Uint", 0)
iBitmap := NumGet(btn, 0), idn := NumGet(btn, 4), Statyle := NumGet(btn, 8)
dwData := NumGet(btn,12), iString := NumGet(btn,16)
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 24, "Uint", 0)
hWnd := NumGet(nfo, 0), uID := NumGet(nfo, 4)
nMsg := NumGet(nfo, 8)
WinGet, pid, PID, ahk_id %hWnd%
WinGet, sProcess, ProcessName, ahk_id %hWnd%
WinGetClass, sClass, ahk_id %hWnd%
If !sExeName || (sExeName = sProcess) || (sExeName = pid)
{
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString
, "Uint", &wTooltip, "Uint", 128 * 2, "Uint", 0)
DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip
, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
sTrayIcons .= nMsg "|" uID "|" hWnd
}
}
DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
DllCall("CloseHandle", "Uint", hProc)
Return sTrayIcons
}


;Outlook on the Desktop-----------------------END OF SCRIPT------------------------------------------------------------------------------
BlockInput, on
pos := Tray_Define("CCC.exe", "i")
Tray_Click(pos, "R")
WinWait, ahk_class #32768
; WinHide, ahk_class #32768 ;this and next line are to hide the menu.
; WinKill, ahk_class SysShadow
ControlSend,,{Down}{Down}{Down}{Down}{Down}{ENTER},ahk_class #32768
BlockInput, off
ExitApp
现在我又在谷歌上搜索了一些,找到了以下脚本:

;#NoTrayIcon
DetectHiddenWindows, On

;Outlook on the Desktop--------------------------------------------------------------------------------------------------------------------------------

^1:: ;25,000$ Fine Tuned

Info := TrayIcons("OutlookDesktop.exe") ; OutlookDesktop.exe is the prog i tested with
StringSplit, TrayInfo, Info,|
PostMessage, TrayInfo1, TrayInfo2, 0x0205,, ahk_id %TrayInfo3% ; this is the right-click
Sleep 500
Send {Down 3}{Right}{Down 7}{Right}{Down 4}{Enter}
return

^2:: ;Projects

Info := TrayIcons("OutlookDesktop.exe") ; OutlookDesktop.exe is the prog i tested with
StringSplit, TrayInfo, Info,|
PostMessage, TrayInfo1, TrayInfo2, 0x0205,, ahk_id %TrayInfo3% ; this is the right-click
Sleep 500
Send {Down 3}{Right}{Down 7}{Right}{Down 1 4}{Enter}
return

^3:: ;Due This Week - unfinished

Info := TrayIcons("OutlookDesktop.exe") ; OutlookDesktop.exe is the prog i tested with
StringSplit, TrayInfo, Info,|
PostMessage, TrayInfo1, TrayInfo2, 0x0205,, ahk_id %TrayInfo3% ; this is the right-click
Sleep 500
Send {Down 3}{Right}{Down 7}{Right}{Down 2 4}{Enter}
return

^4:: ;To-do Bar Calendar View

Info := TrayIcons("OutlookDesktop.exe") ; OutlookDesktop.exe is the prog i tested with
StringSplit, TrayInfo, Info,|
PostMessage, TrayInfo1, TrayInfo2, 0x0205,, ahk_id %TrayInfo3% ; this is the right-click
Sleep 500
Send {Down 3}{Right}{Down 7}{Right}{Down 7 4}{Enter}
return

; Found and abused from
; http://www.autohotkey.com/forum/topic17314.html
; thx, Sean ... GREAT WORK!

TrayIcons(sExeName = "OutlookDesktop.exe")
{
WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
pRB := DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0
, "Uint", 20, "Uint", 0x1000, "Uint", 0x4)
VarSetCapacity(btn, 20)
VarSetCapacity(nfo, 24)
VarSetCapacity(sTooltip, 128)
VarSetCapacity(wTooltip, 128 * 2)
SendMessage, 0x418, 0, 0, ToolbarWindow32, ahk_class Shell_TrayWnd
Loop, %ErrorLevel%
{
SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32, ahk_class Shell_TrayWnd
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pRB, "Uint", &btn, "Uint", 20, "Uint", 0)
iBitmap := NumGet(btn, 0), idn := NumGet(btn, 4), Statyle := NumGet(btn, 8)
dwData := NumGet(btn,12), iString := NumGet(btn,16)
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 24, "Uint", 0)
hWnd := NumGet(nfo, 0), uID := NumGet(nfo, 4)
nMsg := NumGet(nfo, 8)
WinGet, pid, PID, ahk_id %hWnd%
WinGet, sProcess, ProcessName, ahk_id %hWnd%
WinGetClass, sClass, ahk_id %hWnd%
If !sExeName || (sExeName = sProcess) || (sExeName = pid)
{
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString
, "Uint", &wTooltip, "Uint", 128 * 2, "Uint", 0)
DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip
, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
sTrayIcons .= nMsg "|" uID "|" hWnd
}
}
DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
DllCall("CloseHandle", "Uint", hProc)
Return sTrayIcons
}


;Outlook on the Desktop-----------------------END OF SCRIPT------------------------------------------------------------------------------
BlockInput, on
pos := Tray_Define("CCC.exe", "i")
Tray_Click(pos, "R")
WinWait, ahk_class #32768
; WinHide, ahk_class #32768 ;this and next line are to hide the menu.
; WinKill, ahk_class SysShadow
ControlSend,,{Down}{Down}{Down}{Down}{Down}{ENTER},ahk_class #32768
BlockInput, off
ExitApp
有趣的是,该脚本在Catalyst Control Centar(CCC.exe)上运行得非常好,但在我希望它运行的程序上却无法运行,它成功地右键单击,但发送控制命令却无法运行。(也尝试使用just Send而不是ControlSend)


你们认为这里的问题是什么,为什么ControlSend和Send命令不起作用?你建议我试试什么?

这是一个部分答案:

自Windows 7以来,AHK必须始终以管理员身份运行,否则它会显示奇怪的行为(有时不监听热键,有时不发送键)


请用BlockIntput将您的观点发布到另一个答案中。

为了排除一个问题,您可以尝试运行提升到管理员权限的脚本吗?刚刚尝试了您的建议,当设置为以管理员身份运行时,它冻结(无法移动鼠标,但键盘工作)必须按住ctrl键,然后运行任务管理器,突然鼠标工作!你认为这里发生了什么?这很奇怪……哇,在可预见的未来,我又有了一个坚持使用Windows7(带经典Shell)的理由。。。。我有时不得不将AHK提升为管理员,但从未遇到过这些(鼠标冻结)问题,所以很不幸,我无法进一步帮助您。只需简单查看一下您的脚本。您是否意识到在第二个脚本中,您要做的第一件事是阻止所有用户输入。所以我很困惑为什么键盘还能工作,但这可以解释你的鼠标行为。同样在controlsend中,您只指定窗口AHK_类,而不是窗口对象。您是否已将AHK_类更改为要控制的应用程序(使用AHK Spy查找AHK_类)。谢谢您的提示!我换了阿库班,这是整个故事中的问题,我太短视了,再次感谢!