Jump to content

MouseGetPos() - Desktop area


Recommended Posts

Hi guys, i have some problem with this script:

#include <Misc.au3>

Test()

Func Test()
Local $Position = MouseGetPos()
While Not _IsPressed("1B") ; ESC button
  $Final = MouseGetPos()
  $LeftSX = @DesktopWidth/4
  $Top = @DesktopHeight/4
  TrayTip("", "Top: " & $Top & @CRLF & "Left:" & $LeftSX & @CRLF & "FinalPosition: " & $Final[0], "")
  If _IsPressed("01") Then
   If $Final[0] <= $LeftSX AND $Final[0] <= $Top Then
    MsgBox(0, 0, "Test")
   EndIf
  EndIf
  Sleep(100)
WEnd
Return
Sleep(1000)
EndFunc   ;==>Test

I want to set two areas ( one on left-down, one on right-top) and make an event on click. I don't know how to set the top position ( now work only for all left area ) and if i have to make the second area on Top-right in the same While-WEnd. I there is a way to improve it plase ask

Thanks for advice :)

Edited by johnmcloud
Link to comment
Share on other sites

Try this out for size and see if it's what you're looking for.

#include <MISC.AU3>
#include <Misc.au3>

Test()

Func Test()
    Local $Position = MouseGetPos()
    $LeftSX = @DesktopWidth / 4 ; only needs to be declared once, not every time through the loop
    $Top = @DesktopHeight / 4  ; only needs to be declared once, not every time through the loop
    $Final = MouseGetPos() ; prevents the tray tip from causing an error first time through the loop
    While Not _IsPressed("1B") ; ESC button
        TrayTip("", "Top: " & $Top & @CRLF & "Left:" & $LeftSX & @CRLF & "FinalPosition: " & $Final[0] & ":" & $Final[1], "")
        If _IsPressed("01") Then
            $Final = MouseGetPos(); added so that $Final is up to date when the button is pressed.
            If $Final[1] <= $LeftSX And $Final[0] <= $Top Then ; <<<<<<<<Changed the order of the Mouse X/Y around
                MsgBox(0, 0, "Test")
            EndIf
        EndIf
        Sleep(100)
    WEnd
    Return
    Sleep(1000)
EndFunc   ;==>Test
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks BrewManNH, in your script is Top-Left, how to make Down-Left / Down-Right etc?

I just noticed the @Desktop included the Start bar, there is a way to remove it with absolute value?

Thanks :)

EDIT: Sees something not work, for top isn't precise:

I have a msgbox in this area:

Posted Image

It's out of 150, i have it until 200

EDIT2: Left is top and Top is left ;)

Is precise, no problem

Edited by johnmcloud
Link to comment
Share on other sites

Fixed the code that I put above and added the other 3 corners.

#include <MISC.AU3>
#include <Misc.au3>

Test()

Func Test()
    Local $Position = MouseGetPos()
    $LeftSX = @DesktopWidth / 4 ; only needs to be declared once, not every time through the loop
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $LeftSX = ' & $LeftSX & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    $Top = @DesktopHeight / 4 ; only needs to be declared once, not every time through the loop
    $Final = MouseGetPos() ; prevents the tray tip from causing an error first time through the loop
    While Not _IsPressed("1B") ; ESC button
        TrayTip("",  "Left:" & $LeftSX & @CRLF & "Top: " & $Top & @CRLF & "FinalPosition: " & $Final[0] & ":" & $Final[1], "")
        If _IsPressed("01") Then
            $Final = MouseGetPos(); added so that $Final is up to date when the button is pressed.
            If $Final[0] <= $LeftSX And $Final[1] <= $Top Then
                MsgBox(0, 0, "Top Left")
            ElseIf $Final[0] <= $LeftSX And $Final[1] >= ($Top * 3) Then
                MsgBox(0, 0, "Bottom Left")
            ElseIf $Final[0] >= ($LeftSX * 3) And $Final[1] <= $Top Then
                MsgBox(0, 0, "Top Right")
            ElseIf $Final[0] >= ($LeftSX * 3) And $Final[1] >= ($Top * 3) Then
                MsgBox(0, 0, "Bottom Right")
            EndIf
        EndIf
        Sleep(100)
    WEnd
    Return
    Sleep(1000)
EndFunc   ;==>Test

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Perfect. I have little edited for remove the Startbar from the desktop macro:

#include <WinAPI.au3>
#include <Misc.au3>

Test()

Func Test()
Local $Position = MouseGetPos()
$LeftSX = _GetworkingAreaWidth() / 4 ; only needs to be declared once, not every time through the loop
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $LeftSX = ' & $LeftSX & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$Top = _GetworkingAreaHeight() / 4 ; only needs to be declared once, not every time through the loop
$Final = MouseGetPos() ; prevents the tray tip from causing an error first time through the loop
While Not _IsPressed("1B") ; ESC button
  TrayTip("", "Left:" & $LeftSX & @CRLF & "Top: " & $Top & @CRLF & "FinalPosition: " & $Final[0] & ":" & $Final[1], "")
  If _IsPressed("01") Then
   $Final = MouseGetPos(); added so that $Final is up to date when the button is pressed.
   If $Final[0] <= $LeftSX And $Final[1] <= $Top Then
    MsgBox(0, 0, "Top Left")
   ElseIf $Final[0] <= $LeftSX And $Final[1] >= ($Top * 3) Then
    MsgBox(0, 0, "Bottom Left")
   ElseIf $Final[0] >= ($LeftSX * 3) And $Final[1] <= $Top Then
    MsgBox(0, 0, "Top Right")
   ElseIf $Final[0] >= ($LeftSX * 3) And $Final[1] >= ($Top * 3) Then
    MsgBox(0, 0, "Bottom Right")
   EndIf
  EndIf
  Sleep(100)
WEnd
Return
Sleep(1000)
EndFunc   ;==>Test

Func _GetworkingAreaWidth()
Local $aRect[4]
Local $iWidth = 0
$aRect = _GetworkingAreaRect()
If Not @error Then
  $iWidth = $aRect[2] - $aRect[0]
  Return $iWidth
Else
  Return SetError(1, 0, 0)
EndIf
EndFunc   ;==>_GetworkingAreaWidth

Func _GetworkingAreaHeight()
Local $aRect[4]
Local $iWidth = 0
$aRect = _GetworkingAreaRect()
If Not @error Then
  $iWidth = $aRect[3] - $aRect[1]
  Return $iWidth
Else
  Return SetError(1, 0, 0)
EndIf
EndFunc   ;==>_GetworkingAreaHeight

Func _GetworkingAreaRect()
Local $aRect[4]
Const $SPI_GETWORKAREA = 0x0030
Local $rect = DllStructCreate("int;int;int;int")
Local $iResult = 0
$iResult = _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($rect))
If $iResult Then
  $aRect[0] = DllStructGetData($rect, 1)
  $aRect[1] = DllStructGetData($rect, 2)
  $aRect[2] = DllStructGetData($rect, 3)
  $aRect[3] = DllStructGetData($rect, 4)
  Return $aRect
Else
  Return SetError(1, 0, 0)
EndIf
EndFunc   ;==>_GetworkingAreaRect
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

×
×
  • Create New...