Jump to content
Sign in to follow this  
johnmcloud

MouseGetPos() - Desktop area

Recommended Posts

johnmcloud

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

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
johnmcloud

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

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
johnmcloud

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

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • davidacrozier
      By davidacrozier
      I am attempting to drag and drop a file from one windows explorer window to another windows explorer window (henceforth referred to as window1 and window2).  I am not using the web.  I have used autowinexp.au3 (taken from LarsJ's automatewindowsexplorer.au3) to give focus (function GetFileFocus)  to a file on window1.   The problem is that sometimes the file with the focus is not displayed on window1 because it is farther down the list than what is displayed in window1.  There are other ways to accomplish this (like copy and paste) but I want to emulate the GUI doing a drag and drop.  I work as a digital forensicator and my task is to examine what artifacts are left behind on move/copy vs a drag and drop.  Please note that when I open window1 and window2 they are on top of each other, so I drag window2 over about 1150 pixels and that part works great.    
      My code is listed below.  Please understand that I have tried several different methods to accomplish this task.  The last one was to estimate that the top of the window1 header is approximately 320 pixels and to multiply the index of the file by 20 pixels since that appears to be the approximate height of individual files using the AutoIT Windows Info tool.  Ideally the program would search window1 for the file name text and provide a mouse position for it.  Or the program would allow me to scroll to where the file name is located.  Any and all ideas are welcome.
      Using Windows 10
      AutoIT v3.3.14.2
      Thanks!
      DavidaCrozier
      PS Any problems in autowinexp.au3 are mine and not the author of automatewindowsexplorer.au3.  
       
      DragAndDropForum.au3
      autowinexp.au3
    • autog
      By autog
      I left a comment in another thread on multitouch, but my question can be missed there and the solution might have no relationship with simulating multi-touch.
      So, is there any possibility to get the multiple x,y coordinates on a multi-touch device?
      Smth like mousegetpos, but multiple (?)
      Thank you for any idea / direction towards a solution.
    • DiveHigh
      By DiveHigh
      Hello There!  
      I've encountered a small issue i just cant seem to program my way out of...

      What im doing is:        ;or rather, what im trying to do is
      Pixelsearch for a color, within a part of my screen,
      If color is present, i will rightclick it, for a menu to appear,
      in which i want to Leftclick an option. Simplicity itself.   

      The issue is that because this menu appears in different parts of my screen, its complicated to select the option i want to click.
      There is no special color to it, and i cannot define the area in which to click, because the menu appears different places.
      The only thing that is in common for the menu is that the Leftclick needs to be (lets say) 30pixels below the rightclick
      .

      What can be done,  but seemingly not by me, is to get the coordinates of the rightclick, and use them as the "starting point" from where the coordinates for the leftclick will be.
      (Not sure if that makes sence, but maybe the code below will help you understand)

      You guys like example codes, so therefore i will give it my best shot, and hope it proves usefull

      $pos = Pixelsearch(200, 400, 200, 400, 0xFFFFFF)        ;This color is what i need to rightclick to bring up the menu
      If not @Error then                                                               ;If the color is present
      (Mouseclick("Right", $pos[0], $pos[1], 1, 1)                   ;Rightclick it, to bring up menu
      ;Here comes the part i cannot get to work
      $x = MousegetPos(X)                                                          ;To get the Coordinate "X", so we can calculated with it for the position of the leftclick
      $y = MousegetPos(Y)                                                           ; To get the Coordinate "Y", so that can be calculated with for the position of the leftclick

      MouseClick("Left", $x[0], $y-30[1], 1, 1)                         ;This was supposed to give me a leftclick that is 30pixels below the rightclick.
      (The MouseGetPos(X), may seem as a waste of space in this example, but in my script i will need both. 
              Im only using one in the example, mainly so that i wont confuse myself, but also to make it easier to digest for you guys)


      I have not been able to find any topic that covers this, but my apologies if such a topic already exist in the forums. 

      Maybe while im at it, can i ask,   what good does the [0] and [1] do, when using a "$variable" as coordinate?   


      Thanks in advance
      - DiveHigh
    • K3STROS
      By K3STROS
      How would i go about saving a mouse position into a variable, atm i have this but im really not sure if its the proper way to do it
      Im still very new to this
       
      Global $xyLocation = MouseGetPos() $Start_Exit_GUI = GUICreate("EXAMPLE", 228, 194, 398, 222) GUISetBkColor(0x0000FF) $Loc_Button = GUICtrlCreateButton("GET LOCATION", 0, 0, 227, 89, $WS_GROUP) GUICtrlSetFont(-1, 28, 400, 0, "Absolute Zero") $Exit_Button = GUICtrlCreateButton("EXIT", 0, 96, 227, 97, $WS_GROUP) GUICtrlSetFont(-1, 28, 400, 0, "Absolute Zero") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Loc_Botton LocButton() Case $Exit_Button Terminate() EndSwitch WEnd Func LocButton() MsgBox(0, "NOTICE", "Click on the Location you want") MouseClick($xyLocation[0],$xyLocation[1] MsgBox(0, "LOCATION","Location has been set") EndFunc Func Terminate() Exit 1 EndFunc  
       
      I want $xyLocation to hold whatever x-y Coordinates from where the user clicks AFTER the MsgBox() is gone
       
      Thanks in advance for any help
×