With Desktop Composition Disabled,My Usual Choice.
- 0.000057
0.066316
- 0.023350
50.509178
Code: Select all
#SingleInstance, Force
#NoTrayIcon
#KeyHistory, 0
#MaxThreadsPerHotkey, 1
#Persistent
#MaxMem 1000
ListLines, Off
SetBatchLines, -1
SetWinDelay, -1
SetMouseDelay, -1
SetKeyDelay, -1, -1
SetTitleMatchMode, 3
DetectHiddenWindows, On
Process, Priority,, High ; Have the script set itself to high priority. Use this setting with caution. It's been known to cause problems with lower end PC's
/*
With Desktop Composition Disabled,My Usual Choice.
0.000057
0.066316
With Desktop Composition Enabled
0.023350
50.509178
*/
MsgBox % Clipboard := QPXF(1,"GetPixelColor",0,0) "`n" QPXF(1,"GetPixelMonochromeText",,,20,20)
trimWhiteSpace := false ;removes all lines that contain only a single character,such as blank lines in output
;create monospaced font,attach to never displayed static object and set font to active ToolTip
;credit: uname ;forgot the post where he/she posted it at.
text :="sometext"
Gui Font,, Lucida Console ;a monospaced font
Gui, Add, Text, HwndhwndStatic, % text
SendMessage, 0x31,,,, ahk_id %hwndStatic%
font := ErrorLevel, clipboard := font
;SendMessage, 0x30, font, 1,, ahk_class tooltips_class32 ahk_exe AutoHotkey.exe ;set ToolTip font to that of gui object.
Loop{
ToolTip % txt := !trimWhiteSpace ? GetPixelMonochromeText(,,40,20) : StringRemoveSingleCharLine(GetPixelMonochromeText(,,40,20))
SendMessage, 0x30, font, 1,, ahk_class tooltips_class32 ahk_exe AutoHotkey.exe ;set ToolTip font to monospace
}
GetPixelMonochromeText(x:="",y:="",w:=50,h:=50){
threshold := 65, invert := false, dark := !invert ? "0" : "-", light := !invert ? "-" : "0"
,invertOutput:=true ;invert any output to have a high contrast image
If !x
MouseGetPos, x, y
x := x-(w/2), y:= y-(h/2)
Loop % Round(h){
thisY := A_Index
Loop % Round(w){
rgb := GetPixelColor(x+A_Index,y+thisY)
,imageMatrix .= (rgb.Red > threshold AND rgb.Green > threshold AND rgb.Blue > threshold ? light : dark)
}
imageMatrix .= "`n"
}
;if dominant char is 0, invert char set for better contrast
( StringCharCount(imageMatrix,dark)/StrLen(imageMatrix) > 0.5 ? (imageMatrix := StrReplace(imageMatrix,light,"~")) & (imageMatrix := StrReplace(imageMatrix,dark,light)) & (imageMatrix := StrReplace(imageMatrix,"~",dark)) : "" )
Return imageMatrix
}
Loop{
MouseGetPos, x, y
rgb := GetPixelColor(x,y)
ToolTip % whiteShade := ColorDistance(rgb.Red . rgb.Green . rgb.Blue,255255255), 0,0,2 ;white
ToolTip % blackShade := ColorDistance(rgb.Red . rgb.Green . rgb.Blue,000), 0,30,3 ;black
ToolTip % rgb.Red "`n" rgb.Green "`n" rgb.Blue
;where true black = 0B & 65W and true white = 495B & 0W
ToolTip % ( whiteShade < 200 AND blackShade > 200 ? "LIGHT" : "DARK" ), 0,50,4
}
GetPixelColor(x,y){
PixelGetColor, color, %x%, %y%
Blue:="0x" SubStr(color,3,2) ;substr is to get the piece
,Blue:=Blue+0 ;add 0 is to convert it to the current number format
,Green:="0x" SubStr(color,5,2)
,Green:=Green+0
,Red:="0x" SubStr(color,7,2)
,Red:=Red+0
Return {Red:Red, Green:Green, Blue:Blue}
}
ColorDistance(rbg1, rbg2) ;color range measurement
{
return abs((rbg1 & 0xff) - (rbg2 & 0xff)
+ abs(((rbg1 >> 8) & 0xff) - ((rbg2 >> 8) & 0xff))
+ abs(((rbg1 >> 16) & 0xff) - ((rbg2 >> 16) & 0xff))) ;
}
;Returns the number of ooccurrences of a character in a string
StringCharCount(string, char){
StringReplace, string, string, %char%, %char%, UseErrorLevel
Return ErrorLevel
}
StringRemoveSingleCharLine(ByRef list, delim:="`n"){ ;remove lines that contain only a single character
For k,v in StrSplit(list, delim)
nList .= StringCharCount(v,SubStr(v,1,1)) = StrLen(v) ? "" : (!nList ? v : "`n" v)
Return nList
}
; QPXF(<passes>, <function name>, <parameter 1>, ..., <parameter 8>)
QPXF(_P, _F, _1=" ", _2=" ", _3=" ", _4=" ", _5=" ", _6=" ", _7=" ", _8=" "){
If not (IsFunc(_F) || _P > 0)
Return
Loop, %_P%
{
If (_1 = " ")
QPX(True), %_F%()
else If (_8 != " ")
QPX(True), %_F%(_1,_2,_3,_4,_5,_6,_7,_8)
else If (_7 != " ")
QPX(True), %_F%(_1,_2,_3,_4,_5,_6,_7)
else If (_6 != " ")
QPX(True), %_F%(_1,_2,_3,_4,_5,_6)
else If (_5 != " ")
QPX(True), %_F%(_1,_2,_3,_4,_5)
else If (_4 != " ")
QPX(True), %_F%(_1,_2,_3,_4)
else If (_3 != " ")
QPX(True), %_F%(_1,_2,_3)
else If (_2 != " ")
QPX(True), %_F%(_1,_2)
else If (_1 != " ")
QPX(True), %_F%(_1)
T += QPX(False)
}
Return T / _P
}
/*
;;** Basic Usage **
QPX( True ) ; Initialise Counter
Sleep 1000
Ti := QPX( False ) ; Retrieve Time consumed ( & reset internal vars )
MsgBox, 0, Sleep 1000, %Ti% seconds
;;** Extended Usage **
While QPX( 1000 ) ; Loops 1000 times and keeps internal track of the total time
Tooltip %A_Index%
Ti := QPX() ; Retrieve Avg time consumed per iteration ( & reset internal vars )
MsgBox, 0, Avg Time Taken for ToolTip, %Ti% Seconds / Iteration
MsgBox, % Delay( 0.008 ) ; Delay for 8ms
*/
QPX( N=0 ) { ; Wrapper for QueryPerformanceCounter()by SKAN | CD: 06/Dec/2009
Static F,A,Q,P,X ; www.autohotkey.com/forum/viewtopic.php?t=52083 | LM: 10/Dec/2009
If ( N && !P )
Return DllCall("QueryPerformanceFrequency",Int64P,F) + (X:=A:=0) + DllCall("QueryPerformanceCounter",Int64P,P)
DllCall("QueryPerformanceCounter",Int64P,Q), A:=A+Q-P, P:=Q, X:=X+1
Return ( N && X=N ) ? (X:=X-1)<<64 : ( N=0 && (R:=A/X/F) ) ? ( R + (A:=P:=X:=0) ) : 1
}