anchelito
Joined: 26 Dec 2007 Posts: 8
|
Posted: Thu Dec 27, 2007 6:17 pm Post subject: WinActivate sometimes does not activate,or just topmost |
|
|
with the help of a script i found in the forum for detecting the order of the taskbar-items i created a script, that overrides the F-keys, so that they activate the window of the corresponding item in the taskbar. (very useful for navigating between windows, especially if you have a vertical taskbar) a double-press of the f-key will execute the normal f-key-action.
now there are some problems:
1.) sometimes the item won't be activated. this happens randomly and has to do with the program. I experienced this with UltraExplorer
2.) some program-windows will never be activated: f. ex. MP3Gain
3.) some program-windows become topmost, but stay inactive until i click in, f. ex. Notepad++
well ... here is my code:
| Code: |
GetTaskSwBar()
{
WinGet, ControlList, ControlList, ahk_class Shell_TrayWnd
RegExMatch(ControlList, "(?<=ToolbarWindow32)\d+(?!.*ToolbarWindow32)", nTB)
Loop, %nTB%
{
ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
hParent := DllCall("GetParent", "Uint", hWnd)
WinGetClass, sClass, ahk_id %hParent%
If (sClass <> "MSTaskSwWClass")
Continue
idxTB := A_Index
Break
}
Return idxTB
}
; ---------------------
#WinActivateForce
sendFirst = false
ActivateWindow(idx){
idxTB := GetTaskSwBar()
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(sTooltip, 128)
VarSetCapacity(wTooltip, 128 * 2)
SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_BUTTONCOUNT
ArrayCount = 0
Loop, %ErrorLevel%
{
SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_GETBUTTON
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, "UintP", hWnd, "Uint", 4, "Uint", 0)
If !hWnd
Continue
WinGet, pid, PID, ahk_id %hWnd%
WinGet, sProcess, ProcessName, ahk_id %hWnd%
WinGetClass, sClass, ahk_id %hWnd%
If !sExeName || (sExeName = sProcess) || (sExeName = pid)
{
ArrayCount += 1
; put the pid's into an array to have a correct order
pids%ArrayCount% := pid
}
}
DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
DllCall("CloseHandle", "Uint", hProc)
; activate the window
thePid := pids%idx%
WinActivate, ahk_pid %thePid%
}
singlePlusDoublePress(key, window, time){
KeyWait, %key% ; wait for key to be released
KeyWait, %key%, D T%time% ; and pressed again within "time" seconds
if (ErrorLevel){ ; timed-out (only a single press)
if(sendFirst){ ; which command first???
Send {%key%}
} else {
ActivateWindow(window)
}
}else{
if(sendFirst){
ActivateWindow(window)
} else {
Send {%key%}
}
}
}
dblPressTime := 0.1
$F1::
singlePlusDoublePress("F1", 1, dblPressTime)
return
$F2::
singlePlusDoublePress("F2", 2, dblPressTime)
return
$F3::
singlePlusDoublePress("F3", 3, dblPressTime)
return
$F4::
singlePlusDoublePress("F4", 4, dblPressTime)
return
$F5::
singlePlusDoublePress("F5", 5, dblPressTime)
return
$F6::
singlePlusDoublePress("F6", 6, dblPressTime)
return
$F7::
singlePlusDoublePress("F7", 7, dblPressTime)
return
$F8::
singlePlusDoublePress("F8", 8, dblPressTime)
return
$F9::
singlePlusDoublePress("F9", 9, dblPressTime)
return
$F10::
singlePlusDoublePress("F10", 10, dblPressTime)
return
$F11:
singlePlusDoublePress("F11", 11, dblPressTime)
return
$F12::
singlePlusDoublePress("F12", 12, dblPressTime)
return
|
can you see the error??
thank you very much.
and sorry for the bad code-style - i am a total ahk-scripting-newbie.
greetings,
anchelito |
|