0
votes

I recently upgraded to Windows 8.1 x64, now script that i was using doesn't work anymore. That script would right click tray icon of a certain program than navigate to one of its options then click that option.

Here is the script:::

;#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------------------------------------------------------------------------------

Now i googled some more and found this 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

Interestingly enough, script is working perfectly on Catalyst Control Centar (CCC.exe) but not on that program i want it to work on, it successfully right clicks but sending control commands is not working. (Also have tried with just Send instead of ControlSend)

What do you guys think is the problem here, why are ControlSend and Send commands not working? What do you suggest that i try?

1
Just to exclude one issue, could you try to run your script elevated to admin rights?Robert Ilbrink
Just tried your suggestion and when set to run as administrator it freezes (cannot move mouse but keyboard working) have to ctrl_alt_del then run task manager, suddenly mouse is working! What do you suggest is happening here? This is very strange...Ve-Khan
Wow, one more reason for me to stick to Windows 7 (with classic Shell) for the foreseeable future.... I sometimes have to elevate AHK to admin, but never ran into these (mouse freezing) issues, so unfortunately, I can't help you any further.Robert Ilbrink
Just briefly looked at your script. Do you realize that in the second script, the first thing you do is to BLOCK all User input. So I am puzzled why the keyboard still worked,but this would explain your mouse behaviour. Also in the controlsend, you only specify the window AHK_Class, not the window object. Have you changed the AHK_class to the app you want to control (use AHK Spy to find the AHK_Class).Robert Ilbrink
Thanks for the tip! I have changed ahk_class, that was the problem in the whole story, so shortsighted of me, thanks yet again!Ve-Khan

1 Answers

2
votes

This is an partial answer:

Since Windows 7, AHK must be always run as administrator, otherwise it shows strange behavior (sometimes not listening to hotkeys, sometimes not sending keys).

Please post your point with BlockIntput into another answer.