Jump to content

mousecandle 1.1 *updated*


corgano
 Share

Recommended Posts

@ corgano your function is still not working for me! Is crashing after 8 10 seconds if I move the mouse. My screen 1920x1200 is not complete black, I see a small stripe of my desktop on the right side.

@ UEZ your function is working for me.

thats odd. its width is suposed to be screen width + 30........

are you useing the newest beta autoit?

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

I've tested it on my dual monitor and it didn't work properly. The mouse and the "hole" are not on same position because of virtual screen size. :)

Here the corrected code:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 78);sm_virtualwidth
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 79);sm_virtualheight
$VirtualDesktopHeight = $VirtualDesktopHeight[0]
$VirtualDesktopX = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 76);sm_xvirtualscreen
$VirtualDesktopX = $VirtualDesktopX[0]
$VirtualDesktopY = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 77);sm_yvirtualscreen
$VirtualDesktopY = $VirtualDesktopY[0]

Global $hGUI = GUICreate("Test", $VirtualDesktopWidth, $VirtualDesktopHeight, $VirtualDesktopX, $VirtualDesktopY, $WS_POPUP, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
HotKeySet("{ESC}", "Quit")
GUISetBkColor (0x000000)
GUISetState(@SW_SHOW)

While 1
    $diameter = 200
    $radius = $diameter / 2
    $pos = MouseGetPos()
    _GuiHole($hGUI , Abs($VirtualDesktopX) + $pos[0] - $radius,  Abs($VirtualDesktopY) + $pos[1] - $radius, $diameter)
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Quit() ; exit program
    Exit
EndFunc

Func _GuiHole($h_win, $i_x, $i_y, $i_size) ;modified code by ProgAndy
   Dim $pos, $outer_rgn, $inner_rgn, $wh, $combined_rgn, $ret
   $pos = WinGetPos($h_win)
    $outer_rgn = DllCall("gdi32.dll", "hwnd", "CreateRectRgn", "long", 0, "long", 0, "long", $pos[2], "long", $pos[3])
    If IsArray($outer_rgn) Then
        $inner_rgn = DllCall("gdi32.dll", "hwnd", "CreateEllipticRgn", "long", $i_x, "long", $i_y, "long", $i_x + $i_size, "long", $i_y + $i_size)
        If IsArray($inner_rgn) Then
                DllCall("gdi32.dll", "long", "CombineRgn", "hwnd", $outer_rgn[0], "hwnd", $outer_rgn[0], "hwnd", $inner_rgn[0], "int", 4)
                $ret = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "hwnd", $outer_rgn[0], "int", 1)
;~                 DllCall("gdi32.dll", "long", "DeleteObject", "hwnd", $inner_rgn[0])
                If $ret[0] Then
                    Return 1
                Else
                    Return 0
                EndIf
        Else
            Return 0
        EndIf
    Else
        Return 0
    EndIf
EndFunc ;==>_GuiHole

Whole screen is black, not only main window on primary monitor! :)

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I've tested it on my dual monitor and it didn't work properly. The mouse and the "hole" are not on same position because of virtual screen size. :)

Here the corrected code:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 78);sm_virtualwidth
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 79);sm_virtualheight
$VirtualDesktopHeight = $VirtualDesktopHeight[0]
$VirtualDesktopX = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 76);sm_xvirtualscreen
$VirtualDesktopX = $VirtualDesktopX[0]
$VirtualDesktopY = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 77);sm_yvirtualscreen
$VirtualDesktopY = $VirtualDesktopY[0]

Global $hGUI = GUICreate("Test", $VirtualDesktopWidth, $VirtualDesktopHeight, $VirtualDesktopX, $VirtualDesktopY, $WS_POPUP, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
HotKeySet("{ESC}", "Quit")
GUISetBkColor (0x000000)
GUISetState(@SW_SHOW)

While 1
    $diameter = 200
    $radius = $diameter / 2
    $pos = MouseGetPos()
    _GuiHole($hGUI , Abs($VirtualDesktopX) + $pos[0] - $radius,  Abs($VirtualDesktopY) + $pos[1] - $radius, $diameter)
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Quit() ; exit program
    Exit
EndFunc

Func _GuiHole($h_win, $i_x, $i_y, $i_size) ;modified code by ProgAndy
   Dim $pos, $outer_rgn, $inner_rgn, $wh, $combined_rgn, $ret
   $pos = WinGetPos($h_win)
    $outer_rgn = DllCall("gdi32.dll", "hwnd", "CreateRectRgn", "long", 0, "long", 0, "long", $pos[2], "long", $pos[3])
    If IsArray($outer_rgn) Then
        $inner_rgn = DllCall("gdi32.dll", "hwnd", "CreateEllipticRgn", "long", $i_x, "long", $i_y, "long", $i_x + $i_size, "long", $i_y + $i_size)
        If IsArray($inner_rgn) Then
                DllCall("gdi32.dll", "long", "CombineRgn", "hwnd", $outer_rgn[0], "hwnd", $outer_rgn[0], "hwnd", $inner_rgn[0], "int", 4)
                $ret = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "hwnd", $outer_rgn[0], "int", 1)
;~                 DllCall("gdi32.dll", "long", "DeleteObject", "hwnd", $inner_rgn[0])
                If $ret[0] Then
                    Return 1
                Else
                    Return 0
                EndIf
        Else
            Return 0
        EndIf
    Else
        Return 0
    EndIf
EndFunc ;==>_GuiHole

Whole screen is black, not only main window on primary monitor! :)

UEZ

Works perfectly. xD
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Add

WinSetTrans($hGui,"",20)
just after the
GUISetBkColor (0x000000)
and then you've got something that can "spotlight" a portion of the screen, like some projectors have to draw attention to certain areas.

In fact, I bet somebody with more time on their hands could easily make up a utility that would have different shaped holes with maybe even dynamic resizing & colouring to make a cool screen spotlighter...

Link to comment
Share on other sites

Very cool. I like the latest ver a lot. Works great on my dual screen setup.

edit: My own updated ver. Uses scroll wheel to adjust the size of the guihole. :)

spuds_candle.au3

Edited by spudw2k
Link to comment
Share on other sites

Add #include <WindowsConstants.au3>

Remove dim $WS_EX_TOPMOST, $WS_MAXIMIZE

Replace @DesktopWidth + 10, @DesktopHeight-1, -10, -30,"" ,0x00000008 with @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, 0

The result is a perfect black window that covers up everything including the taskbar as long as the gui is topmost and selected.

[size="1"]Please stop confusing "how to" with "how do"[/size]

Link to comment
Share on other sites

Here all suggestion in one code:

;mixed together by UEZ
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>

Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
Global Const $WM_MOUSEWHEEL = 0x020A ;wheel up/down
Global $diameter = 200

$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 78);sm_virtualwidth
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 79);sm_virtualheight
$VirtualDesktopHeight = $VirtualDesktopHeight[0]
$VirtualDesktopX = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 76);sm_xvirtualscreen
$VirtualDesktopX = $VirtualDesktopX[0]
$VirtualDesktopY = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 77);sm_yvirtualscreen
$VirtualDesktopY = $VirtualDesktopY[0]

$hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)

Global $hGUI = GUICreate("The HOLE", $VirtualDesktopWidth, $VirtualDesktopHeight, $VirtualDesktopX, $VirtualDesktopY, $WS_POPUP, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
HotKeySet("{ESC}", "Quit")
GUISetBkColor (0x000000)
WinSetTrans($hGui,"", 224)
GUISetState(@SW_SHOW)

While 1
    $radius = $diameter / 2
    $pos = MouseGetPos()
    _GuiHole($hGUI , Abs($VirtualDesktopX) + $pos[0] - $radius,  Abs($VirtualDesktopY) + $pos[1] - $radius, $diameter)
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Quit() ; exit program
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
    $hM_Hook[0] = 0
    DllCallbackFree($hKey_Proc)
    $hKey_Proc = 0
    Exit
EndFunc

Func _GuiHole($h_win, $i_x, $i_y, $i_size) ;modified code by ProgAndy
   Dim $pos, $outer_rgn, $inner_rgn, $wh, $combined_rgn, $ret
   $pos = WinGetPos($h_win)
    $outer_rgn = DllCall("gdi32.dll", "hwnd", "CreateRectRgn", "long", 0, "long", 0, "long", $pos[2], "long", $pos[3])
    If IsArray($outer_rgn) Then
        $inner_rgn = DllCall("gdi32.dll", "hwnd", "CreateEllipticRgn", "long", $i_x, "long", $i_y, "long", $i_x + $i_size, "long", $i_y + $i_size)
        If IsArray($inner_rgn) Then
                DllCall("gdi32.dll", "long", "CombineRgn", "hwnd", $outer_rgn[0], "hwnd", $outer_rgn[0], "hwnd", $inner_rgn[0], "int", 4)
                $ret = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "hwnd", $outer_rgn[0], "int", 1)
;~                 DllCall("gdi32.dll", "long", "DeleteObject", "hwnd", $inner_rgn[0])
                If $ret[0] Then
                    Return 1
                Else
                    Return 0
                EndIf
        Else
            Return 0
        EndIf
    Else
        Return 0
    EndIf
EndFunc ;==>_GuiHole

Func _Mouse_Proc($nCode, $wParam, $lParam) ;function called for mouse events..
    ;define local vars
    Local $info, $ptx, $pty, $mouseData, $flags, $time, $dwExtraInfo
    Local $xevent = "Unknown", $xmouseData = ""
   
    If $nCode < 0 Then ;recommended, see http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx
        $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
                "int", $nCode, "ptr", $wParam, "ptr", $lParam) ;recommended
        Return $ret[0]
    EndIf
   
    $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) ;used to get all data in the struct ($lParam is the ptr)
    $ptx = DllStructGetData($info, 1) ;see notes below..
    $pty = DllStructGetData($info, 2)
    $mouseData = DllStructGetData($info, 3)
    $flags = DllStructGetData($info, 4)
    $time = DllStructGetData($info, 5)
    $dwExtraInfo = DllStructGetData($info, 6)

    ;Find which event happened
    Select
        Case $wParam = $WM_MOUSEWHEEL
            If _WinAPI_HiWord($mouseData) > 0 Then
                $xmouseData = "Wheel Forward"
                ConsoleWrite($diameter & @CRLF)
                If $diameter < $VirtualDesktopWidth Then $diameter += 40
            Else
                $xmouseData = "Wheel Backward"
                ConsoleWrite($diameter & @CRLF)
                If $diameter > 0 Then $diameter -= 40
            EndIf
    EndSelect
   
    ;This is recommended instead of Return 0
    $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
            "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    Return $ret[0]
EndFunc   ;==>_Mouse_Proc

@spudw2k: your exit code was not correct initialized :)

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@UEZ: made some changes, too :) change size with SHIFT-Scroll -> scroll wheel not useless in other apps

moved _GUIHole to MouseProc -> doesn't need to update when mouse not moved.

;mixed together by UEZ
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>
#Include <Misc.au3>

Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
Global Const $WM_MOUSEWHEEL = 0x020A ;wheel up/down
Global $diameter = 200

$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 78);sm_virtualwidth
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 79);sm_virtualheight
$VirtualDesktopHeight = $VirtualDesktopHeight[0]
$VirtualDesktopX = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 76);sm_xvirtualscreen
$VirtualDesktopX = $VirtualDesktopX[0]
$VirtualDesktopY = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 77);sm_yvirtualscreen
$VirtualDesktopY = $VirtualDesktopY[0]

$hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)

Global $hGUI = GUICreate("The HOLE", $VirtualDesktopWidth, $VirtualDesktopHeight, $VirtualDesktopX, $VirtualDesktopY, $WS_POPUP, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
HotKeySet("{ESC}", "Quit")
GUISetBkColor (0x000000)
WinSetTrans($hGui,"", 224)
GUISetState(@SW_SHOW)
    $pos = MouseGetPos()
    _GuiHole($hGUI , Abs($VirtualDesktopX) + $pos[0] - 100,  Abs($VirtualDesktopY) + $pos[1] - 100, $diameter)
While 1
;~     $radius = $diameter / 2
;~     $pos = MouseGetPos()
;~     _GuiHole($hGUI , Abs($VirtualDesktopX) + $pos[0] - $radius,  Abs($VirtualDesktopY) + $pos[1] - $radius, $diameter)
;~     Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Quit() ; exit program
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
    $hM_Hook[0] = 0
    DllCallbackFree($hKey_Proc)
    $hKey_Proc = 0
    Exit
EndFunc

Func _GuiHole($h_win, $i_x, $i_y, $i_size) ;modified code by ProgAndy
   Dim $pos, $outer_rgn, $inner_rgn, $wh, $combined_rgn, $ret
   $pos = WinGetPos($h_win)
    $outer_rgn = DllCall("gdi32.dll", "hwnd", "CreateRectRgn", "long", 0, "long", 0, "long", $pos[2], "long", $pos[3])
    If IsArray($outer_rgn) Then
        $inner_rgn = DllCall("gdi32.dll", "hwnd", "CreateEllipticRgn", "long", $i_x, "long", $i_y, "long", $i_x + $i_size, "long", $i_y + $i_size)
        If IsArray($inner_rgn) Then
                DllCall("gdi32.dll", "long", "CombineRgn", "hwnd", $outer_rgn[0], "hwnd", $outer_rgn[0], "hwnd", $inner_rgn[0], "int", 4)
                $ret = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "hwnd", $outer_rgn[0], "int", 1)
;~                 DllCall("gdi32.dll", "long", "DeleteObject", "hwnd", $inner_rgn[0])
                If $ret[0] Then
                    Return 1
                Else
                    Return 0
                EndIf
        Else
            Return 0
        EndIf
    Else
        Return 0
    EndIf
EndFunc ;==>_GuiHole

Func _Mouse_Proc($nCode, $wParam, $lParam) ;function called for mouse events..
    ;define local vars
    Local $info, $ptx, $pty, $mouseData, $flags, $time, $dwExtraInfo
    Local $xevent = "Unknown", $xmouseData = ""
   
    If $nCode < 0 Then ;recommended, see http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx
        $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
                "int", $nCode, "ptr", $wParam, "ptr", $lParam) ;recommended
        Return $ret[0]
    EndIf
   
    $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) ;used to get all data in the struct ($lParam is the ptr)
    $ptx = DllStructGetData($info, 1) ;see notes below..
    $pty = DllStructGetData($info, 2)
    $mouseData = DllStructGetData($info, 3)
    $flags = DllStructGetData($info, 4)
    $time = DllStructGetData($info, 5)
    $dwExtraInfo = DllStructGetData($info, 6)

    ;Find which event happened
    Select
        Case $wParam = $WM_MOUSEWHEEL
            If _IsPressed("10") Then ; If SHIFT pressed
            If _WinAPI_HiWord($mouseData) > 0 Then
                $xmouseData = "Wheel Forward"
                ConsoleWrite($diameter & @CRLF)
                If $diameter < $VirtualDesktopWidth Then $diameter += 40
            Else
                $xmouseData = "Wheel Backward"
                ConsoleWrite($diameter & @CRLF)
                If $diameter > 0 Then $diameter -= 40
            EndIf
            EndIf
    EndSelect
   $radius = $diameter / 2
;~     $pos = MouseGetPos()
;~     _GuiHole($hGUI , Abs($VirtualDesktopX) + $pos[0] - $radius,  Abs($VirtualDesktopY) + $pos[1] - $radius, $diameter)
    _GuiHole($hGUI , Abs($VirtualDesktopX) + $ptx - $radius,  Abs($VirtualDesktopY) + $pty - $radius, $diameter)
    ;This is recommended instead of Return 0
    $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
            "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    Return $ret[0]
EndFunc   ;==>_Mouse_Proc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...