Deep-Silence
Joined: 24 Apr 2009 Posts: 87
|
Posted: Tue Mar 09, 2010 7:04 pm Post subject: BACKGROUNDTASK Containing some nice and useful stuff |
|
|
Searching the forum for a solution i have come across
some nice scripts that worked for me. The problem with that scripts
was that they do not worked on every control i had the mouse over,
when it comes to hover wheel.
Does any Guru out there know if there is a function or what ever, that
works on every control???
I have searched the forum for some other additional Stuff to add
some usefull "code" to a script called BackgroundTask.
There is what i have so far:
| Code: |
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;SendMode Event ; Default old traditional send methode.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Persistent
#SingleInstance force
/*
------------------------------------------------------------------------------------------------------------------------------
Hower Wheel - Section
*/
;http://www.autohotkey.com/forum/topic6772.html
CoordMode Mouse, Screen
WheelTime = 500
WheelDelta:= 120 << 16
WheelMax := 4 * WheelDelta
WheelUp::
Critical
If (A_ThisHotKey <> A_PriorHotKey OR A_TimeSincePriorHotkey > WheelTime)
WCnt = %WheelDelta%
Else If (WCnt < WheelMax)
WCnt+= WheelDelta
MouseGetPos m_x, m_y
hw_m_target := DllCall("WindowFromPoint", "int",m_x, "int",m_y)
SendMessage 0x20A, WCnt, (m_y<<16)|m_x,,ahk_id %hw_m_target% ; WM_MOUSEWHEEL
return
WheelDown::
Critical
If (A_ThisHotKey <> A_PriorHotKey OR A_TimeSincePriorHotkey > WheelTime)
WCnt = %WheelDelta%
Else If (WCnt < WheelMax)
WCnt+= WheelDelta
MouseGetPos m_x, m_y
hw_m_target := DllCall("WindowFromPoint", "int",m_x, "int",m_y)
SendMessage 0x20A,-WCnt, (m_y<<16)|m_x,,ahk_id %hw_m_target% ; WM_MOUSEWHEEL
return
/*
------------------------------------------------------------------------------------------------------------------------------
Turn Monitor(s) On Off - Section
*/
~F3::RapidHotkey("Label_IdleCheck_On", 2, 0.3, 1)
Label_IdleCheck_On:
SetTimer, IdleCheck, 500
Return
~F4::RapidHotkey("Label_IdleCheck_Off", 2, 0.3, 1)
Label_IdleCheck_Off:
SetTimer, IdleCheck, Off
Return
IdleCheck:
If(A_TimeIdle<500)
SendMessage,0x112,0xF170,2,,Program Manager
Return
/*
------------------------------------------------------------------------------------------------------------------------------
Press "ESC" two times to close active Applikation
Script-URL: http://www.autohotkey.com/forum/topic38795.html
Key::RapidHotkey("keystrokes" ;Enter keystrokes here. E.g.: "^o"
, times ;optional. How often the key must be pressed to execute. E.g.: 3
, delay ;optional. How quick the key must be pressed to execute. E.g.: 0.2
, IsLabel) ;optional. specify 1 to indicate that parameter 1 is a label.
;E.g.
~o::RapidHotkey("^o") ;open file dialog if o pressed twice
;To specify several actions , use " as separator and leave times parameter empty.
If press times parameter is omitted, first action would be triggered on 2 presses.
~e::RapidHotkey("#r""#e""#f") ; #r if pressed twice, #e 3 times and so on
;You can specify also one (can be also 1) or separated value for times
~s::RapidHotkey("^s""{F12}""^+s", 5) ;so pressing 5 times = ^s, 6 times = {F12} and so on
;You can also specify separated times value
$x::RapidHotkey("x""#r""#e", "1""5""3")
;use same separator for delay and islabel parameter
*/
~Esc::RapidHotkey("ExitCurrentProgramm", 2, 0.3, 1)
ExitCurrentProgramm:
Send, {ALTDOWN}{F4}{ALTUP}
Return
!ESC::RapidHotkey("MinimizeCurrentApp", 1, 0.3, 1)
MinimizeCurrentApp:
WinMinimize, A
Return
/*
------------------------------------------------------------------------------------------------------------------------------
Help - Section
*/
+ß::RapidHotkey("Label_Show_Help", 1, 0.3, 1)
Label_Show_Help:
Msgbox, Help
Return
/*
MinMax Always on Top - Section
;----------------------------------------------------------
;----------------------------------------------------------
; Based on WinTraymin.ahk
; by Sean
; Right click on button
;min: minimize to tray
;max: Toggle Always on Top
;close: Minimize all windows (show desktop).
;----------------------------------------------------------
;----------------------------------------------------------
; Adding a trayminned trayicon of hWnd: WinTraymin(hWnd,0), where 0 can be omitted.
; Removing all trayminned trayicons: WinTraymin(0,-1).
; Other values than 0 & -1 are reserved for internal use.
;----------------------------------------------------------
/*
;#NoTrayIcon
TrayminOpen:
SetWinDelay, 0
SetFormat, Integer, D
CoordMode, Mouse, Screen
DetectHiddenWindows On
hAHK:=WinExist("ahk_class AutoHotkey ahk_pid " . DllCall("GetCurrentProcessId"))
ShellHook:=DllCall("RegisterWindowMessage","str","SHELLHOOK")
DllCall("RegisterShellHookWindow","Uint",hAHK)
OnExit, TrayminClose
Return
TrayminClose:
DllCall("DeregisterShellHookWindow","Uint",hAHK)
WinTraymin(0,-1)
OnExit
ExitApp
RButton Up::
If h:=WM_NCHITTESTmin()
{ ToolTip, R: Minimize to Tray
SetTimer, RemoveToolTip, 1000
WinTraymin(h)
}
Else Click, % SubStr(A_ThisHotkey,1,1) ; for hotkey: LButton/MButton/RButton
If h:=WM_NCHITTESTmax()
{
ToolTip, R: Toggle AlwaysOnTop
SetTimer, RemoveToolTip, 1000
Winset,AlwaysOnTop,Toggle,A
}
If h:=WM_NCHITTESTminall()
{
ToolTip, R: Minimize All
SetTimer, RemoveToolTip, 1000
WinMinimizeAll
}
Return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
Return
WM_NCHITTESTmin()
{
MouseGetPos, x, y, z
SendMessage, 0x84, 0, (x&0xFFFF)|(y&0xFFFF)<<16,, ahk_id %z%
Return ErrorLevel=8 ? z : ""
}
WM_NCHITTESTmax()
{
MouseGetPos, x, y, z
SendMessage, 0x84, 0, (x&0xFFFF)|(y&0xFFFF)<<16,, ahk_id %z%
Return ErrorLevel=9 ? z : ""
}
WM_NCHITTESTminall()
{
MouseGetPos, x, y, z
SendMessage, 0x84, 0, (x&0xFFFF)|(y&0xFFFF)<<16,, ahk_id %z%
Return ErrorLevel=20 ? z : ""
}
WM_SHELLHOOKMESSAGE(wParam, lParam, nMsg)
{
Critical
If nMsg=1028
{
If wParam=1028
Return
Else If (lParam=0x201||lParam=0x205||lParam=0x207)
WinTraymin(wParam,3)
}
Else If (wParam=1||wParam=2)
WinTraymin(lParam,wParam)
Return 0
}
WinTraymin(hWnd = "", nFlags = "")
{
Local h, ni, fi, uid, pid, hProc, sClass
Static nMsg, nIcons:=0
nMsg ? "" : OnMessage(nMsg:=1028,"WM_SHELLHOOKMESSAGE")
NumPut(hAHK,NumPut(VarSetCapacity(ni,444,0),ni))
If Not nFlags
{
If Not ((hWnd+=0)||hWnd:=DllCall("GetForegroundWindow"))||((h:=DllCall("GetWindow","Uint",hWnd,"Uint",4))&&DllCall("IsWindowVisible","Uint",h)&&!hWnd:=h)||!(VarSetCapacity(sClass,15),DllCall("GetClassNameA","Uint",hWnd,"str",sClass,"Uint",VarSetCapacity(sClass)+1))||sClass=="Shell_TrayWnd"||sClass=="Progman"
Return
OnMessage(ShellHook,"")
WinMinimize, ahk_id %hWnd%
WinHide, ahk_id %hWnd%
Sleep, 100
OnMessage(ShellHook,"WM_SHELLHOOKMESSAGE")
uID:=uID_%hWnd%,uID ? "" : (uID_%hWnd%:=uID:=++nIcons=nMsg ? ++nIcons : nIcons)
hIcon_%uID% ? "" : (VarSetCapacity(fi,352,0),DllCall("GetWindowThreadProcessId","Uint",hWnd,"UintP",pid),DllCall("psapi\GetModuleFileNameExA","Uint",hProc:=DllCall("kernel32\OpenProcess","Uint",0x410,"int",0,"Uint",pid),"Uint",0,"Uint",&fi+12,"Uint",260),DllCall("kernel32\CloseHandle","Uint",hProc),DllCall("shell32\SHGetFileInfoA","Uint",&fi+12,"Uint",0,"Uint",&fi,"Uint",352,"Uint",0x101),hIcon_%uID%:=NumGet(fi)),DllCall("GetWindowTextA","Uint",hWnd,"Uint",NumPut(hIcon_%uID%,NumPut(nMsg,NumPut(1|2|4,NumPut(uID,ni,8)))),"int",64)
Return hWnd_%uID%:=DllCall("shell32\Shell_NotifyIconA","Uint",hWnd_%uID% ? 1 : 0,"Uint",&ni) ? hWnd : DllCall("ShowWindow","Uint",hWnd,"int",5)*0
}
Else If nFlags > 0
{
If (nFlags=3&&uID:=hWnd)
If WinExist("ahk_id " . hWnd:=hWnd_%uID%)
{
WinShow, ahk_id %hWnd%
WinRestore, ahk_id %hWnd%
}
Else nFlags:=2
Else uID:=uID_%hWnd%
Return uID ? (hWnd_%uID% ? (DllCall("shell32\Shell_NotifyIconA","Uint",2,"Uint",NumPut(uID,ni,8)-12),hWnd_%uID%:="") : "",nFlags==2&&hIcon_%uID% ? (DllCall("DestroyIcon","Uint",hIcon_%uID%),hIcon_%uID%:="") : "") : ""
}
Else
Loop, % nIcons
hWnd_%A_Index% ? (DllCall("shell32\Shell_NotifyIconA","Uint",2,"Uint",NumPut(A_Index,ni,8)-12),DllCall("ShowWindow","Uint",hWnd_%A_Index%,"int",5),hWnd_%A_Index%:="") : "",hIcon_%A_Index% ? (DllCall("DestroyIcon","Uint",hIcon_%A_Index%),hIcon_%A_Index%:="") : ""
}
*/
;-----
;-----
ExitApp
;-----
;-----
-
-
;------------------------------------------------------------------------------------------------------------------------------
; RapidHotkey
RapidHotkey(keystroke, times="2", delay=0.2, IsLabel=0)
{
Pattern := Morse(delay*1000)
If (StrLen(Pattern) < 2 and Chr(Asc(times)) != "1")
Return
If (times = "" and InStr(keystroke, """"))
{
Loop, Parse, keystroke,""
If (StrLen(Pattern) = A_Index+1)
continue := A_Index, times := StrLen(Pattern)
}
Else if (RegExMatch(times, "^\d+$") and InStr(keystroke, """"))
{
Loop, Parse, keystroke,""
If (StrLen(Pattern) = A_Index+times-1)
times := StrLen(Pattern), continue := A_Index
}
Else if InStr(times, """")
{
Loop, Parse, times,""
If (StrLen(Pattern) = A_LoopField)
continue := A_Index, times := A_LoopField
}
Else if (times = "")
continue = 1, times = 2
Else if (times = StrLen(Pattern))
continue = 1
If !continue
Return
Loop, Parse, keystroke,""
If (continue = A_Index)
keystr := A_LoopField
Loop, Parse, IsLabel,""
If (continue = A_Index)
IsLabel := A_LoopField
hotkey := RegExReplace(A_ThisHotkey, "[\*\~\$\#\+\!\^]")
IfInString, hotkey, %A_Space%
StringTrimLeft, hotkey,hotkey,% InStr(hotkey,A_Space,1,0)
Loop % times
backspace .= "{Backspace}"
keywait = Ctrl|Alt|Shift|LWin|RWin
Loop, Parse, keywait, |
KeyWait, %A_LoopField%
If ((!IsLabel or (IsLabel and IsLabel(keystr))) and InStr(A_ThisHotkey, "~") and !RegExMatch(A_ThisHotkey
, "i)\^[^\!\d]|![^\d]|#|Control|Ctrl|LCtrl|RCtrl|Shift|RShift|LShift|RWin|LWin|Escape|BackSpace|F\d\d?|"
. "Insert|Esc|Escape|BS|Delete|Home|End|PgDn|PgUp|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|AppsKey|"
. "PrintScreen|CtrlDown|Pause|Break|Help|Sleep|Browser_Back|Browser_Forward|Browser_Refresh|Browser_Stop|"
. "Browser_Search|Browser_Favorites|Browser_Home|Volume_Mute|Volume_Down|Volume_Up|MButton|RButton|LButton|"
. "Media_Next|Media_Prev|Media_Stop|Media_Play_Pause|Launch_Mail|Launch_Media|Launch_App1|Launch_App2"))
SendInput % backspace
If (WinExist("AHK_class #32768") and hotkey = "RButton")
WinClose, AHK_class #32768
If !IsLabel
SendInput % keystr
else if IsLabel(keystr)
Gosub, %keystr%
Return
}
Morse(timeout = 400) { ;by Laszo -> http://www.autohotkey.com/forum/viewtopic.php?t=16951 + Modifications by HotKeyIt
static running
If running
Return
running=1
k:="+AppsKey+Lwin+Rwin+LControl+RControl+LAlt+RAlt+LShift+RShift+Tab+Backspace+Enter+Left+Right"
. "+Up+Down+Delete+Insert+Escape+Home+End+PgUp+PgDn+Numpad0+Numpad1+Numpad2+Numpad3"
. "+Numpad4+Numpad5+Numpad6+Numpad7+Numpad8+Numpad9+NumpadDot+NumpadDiv+NumpadMult+NumpadAdd"
. "+NumpadSub+NumpadEnter+NumpadIns+NumpadEnd+NumpadDown+NumpadPgDn+NumpadLeft+NumpadClear+NumpadRight"
. "+NumpadHome+NumpadUp+NumpadPgUp+NumpadDel+NumpadDiv+NumpadMult+NumpadAdd+NumpadSub+NumpadEnter"
. "+F1+F2+F3+F4+F5+F6+F7+F8+F9+F10+F11+F12+F13+F14+F15+F16+F17+F18+F19"
. "+F20+F21+F22+F23+F24+Pause+Break+PrintScreen+a+b"
. "+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z+0+1"
. "+2+3+4+5+6+7+8+9+Space+´+,+-+."
. "+>+^+RButton+LButton+MButton+Capslock+Scrolllock+Numlock+"
key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
If key=
key:=SubStr(A_ThisHotkey,0)
IfInString, key, %A_Space%
{
StringSplit,key,key,&,% A_Space
If key1=Shift
StringReplace,k,k,+LShift+RShift+, +
else if key1=Alt
StringReplace,k,k,+LAlt+RAlt+, +
else if (key1="Ctrl" || key1="Control")
StringReplace,k,k,+LControl+RControl+, +
else
StringReplace,k,k,% "+" key1 "+", +
StringTrimLeft, key, key,% InStr(key,A_Space,1,0)
}
If key=BS
key=BackSpace
else if key=Esc
key=Escape
else if key=Return
key=Enter
else if key=Ins
key=Insert
else if key=Del
key=Delete
else if key=LCtrl
key=LControl
else if key=RCtrl
key=RControl
If (key="Alt" or InStr(A_ThisHotkey,"!"))
StringReplace,k,k,+LAlt+RAlt+,+
If (key="Ctrl" or key="Control" or InStr(A_ThisHotkey,"^"))
StringReplace,k,k,+LControl+RControl+,+
If (key="Shift" or (InStr(A_ThisHotkey,"+") and key!="+"))
StringReplace,k,k,+LShift+RShift+,+
StringReplace,k,k,+%key%+,+
If (SubStr(k,1,1)="+")
StringTrimLeft,k,k,1
If (SubStr(k,0)="+")
StringTrimRight,k,k,1
StringReplace,k,k,+,% Chr(1),A
If (key!="+")
k .=Chr(1) "+"
Loop {
t := A_TickCount
While % (GetKeyState(key,"P") and A_TickCount-t < timeout){
Sleep, 10
Loop,parse,k,% Chr(1)
If (GetKeyState(A_LoopField,"P") && A_LoopField!=key && running:=0)
Return
}
If (GetKeyState(key,"P") && !running:=0)
Return Pattern . "1"
else
Pattern .=A_TickCount-t > timeout
t := A_TickCount
While % (!GetKeyState(key,"P") and A_TickCount-t < timeout){
Sleep, 10
Loop,parse,k,% Chr(1)
If GetKeyState(A_LoopField,"P")
If (A_LoopField!=key && !running:=0)
Return
else
Break
}
If (!GetKeyState(key,"P") && !running:=0)
Return Pattern
}
}
|
Feel free to enhance it to get the most useful things out of it...
With Best Regards,
Deep-Silence |
|