Sign in to follow this  
Followers 0
IanN1990

Detecting Mouse location on screen

3 posts in this topic

I have 3 screens, i dislike having to go to menus, startbars and all the rest of it to load / open / show applications i use alot.

So when i first started coding, i used the system "Mousegetpos()" to detect where the mouse is and then act on them..

So every 250 ms it checks the mouse pos and then runs this against a list of if statements.

If $Pos[0] < 0 "For left screen"

If $Pos[1] <1 "for left top screen"

Show / Hide Firefox

Elseif $Pos[0] < -1789 "for left side screen"

Show / Hide chat program

Elseif $Pos[1] > 1079 "for left bottom screen"

Show / Hide media player

Endif

Endif

This is just an example of something i threw together fast, because the full code is over 300 lines, and with so many ifs gets very complicated if u dont already understand it :).

So i was wondering is there a better way of detecting when the mouse is in a set location, rather then this very crude way :)

Share this post


Link to post
Share on other sites



I'd say post the code you have so that we could then see if it can be simplified.


A true renaissance man

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hmm ok :) I dont have access to my computer atm as its missing a few parts but i connected to my backup sever and downloaded a slighlty older .au3 version

#NoTrayIcon
Local $ChatHovered
Local $TaskbarHovered
local $TriLoop

while 1
sleep(250)
$SystemMousePosition=MouseGetPos()

         #Region Tri-Screen
            If $SystemMousePosition[0]<0 Then
               If $SystemMousePosition[1]<2 Then
                  $TriLoop += 1
                     If $TriLoop = 3 then
                        If WinGetState('Steam')=23 Then
                           WinSetState('Steam','',@SW_RESTORE)
                        Elseif WinGetState('Steam')=7 or WinGetState('Steam')=15  Then
                           WinSetState('Steam','',@SW_MINIMIZE)
                        Else
                           ControlClick('[Class:Shell_TrayWnd]', 'Running applications', '[CLASS:MSTaskListWClass; INSTANCE:1]', 'right', 1, 126, 120)
                           WinMove('Jump List', '', 0, -1900, 220, 1080,1)
                           ControlSend('Jump List', '', '[CLASS:SysListView32; INSTANCE:1]', '{Down 3}')
                           ControlSend('Jump List', '', '[CLASS:SysListView32; INSTANCE:1]', '{Enter}')
                        Endif
                     $TriLoop = 0
                     EndIf
               Elseif $SystemMousePosition[1]>1077 Then
                  $TriLoop += 1
                     If $TriLoop = 3 then
                        If $SystemMousePosition[0]<-960 Then
                           If WinGetState('[CLASS:Winamp v1.x]')=15 Then
                              Controlclick('[Class:Winamp v1.x]', '', '[CLASS:TSkinPanel; INSTANCE:4]', 'Left', 1, 1825, 15)
                           Else
                              Run('C:Program Files (x86)The KMPlayerKMPlayer.exe')
                           Endif
                        ElseIf WinGetState('[Class:WMPlayerApp]')=23 Then
                        WinSetState('[Class:WMPlayerApp]','',@SW_MAXIMIZE)                    
                        Else
                        WinSetState('[Class:WMPlayerApp]','',@SW_MINIMIZE)
                        WinMove('[Class:WMPlayerApp]', '', 960, 1230)    
                        Endif
                     $TriLoop = 0
                     Endif
               Elseif $SystemMousePosition[0]>-30 Then
                  $TriLoop += 1
                     If $TriLoop = 3 then
                        If $TaskbarHovered=0 Then
                           $TaskbarHovered=1
                           $TaskBarLocation=WinGetPos('[Class:Shell_TrayWnd]')
                           WinSetOnTop('[Class:Shell_TrayWnd]', '', 1)
                           Run('"C:Program Files (x86)AutoIt3AutoIt3.exe" "C:Program Files (x86)ScriptsStorageTaskbarTaskbar.au3"')
                           Sleep(125)
                           If $TaskBarLocation[0]>0 Then MoveTaskbar('Left')            
                           ControlShow('','', WinGetHandle('[CLASS:Button]'))
                           WinSetTrans('[Class:Shell_TrayWnd]', '', 255)
                        EndIf
                     $TriLoop = 0
                     EndIf
               Elseif $TaskBarHovered=1 And $SystemMousePosition[0]<-265  Then
                  If Not(WinActive('Start menu')) And Not(WinGetState('[Class:TaskListThumbnailWnd]')=7) Then
                     $TaskBarHovered=0
                     ControlHide('','', WinGetHandle('[CLASS:Button]'))
                     WinSetTrans('[Class:Shell_TrayWnd]', '', 0)
                  Endif
               Elseif $SystemMousePosition[0]<-1918 Then
                  If $ChatHovered=0 Then
                     $ChatHovered=1
                        If $SystemMousePosition[1]<=360 Then
                           WinMove('[Class:MSBLWindowClass]', '', -1920, 0, 287, 1080,1)
                           WinSetOnTop('[Class:MSBLWindowClass]', '', 1)
                        Elseif $SystemMousePosition[1]>=360 And $SystemMousePosition[1]<=720  Then
                           WinMove('Friends', '', -1920, 0, 287, 1080,1)
                           WinSetOnTop('Friends', '', 1)
                        Elseif $SystemMousePosition[1]>=720 And $SystemMousePosition[1]<=1080 Then
                           Winmove('[Class:tSkMainForm]', '', -1920, 0, 287, 1080,1)
                           WinSetOnTop('[Class:tSkMainForm]', '', 1)
                        Endif    
                  Endif
               Elseif $Chathovered=1 And $SystemMousePosition[0]>-1625 Then
                  $ChatHovered=0
                  WinMove('Friends', '', -2500, 0, 287, 1080,1)
                  WinMove('[Class:MSBLWindowClass]', '', -2500, 0, 287, 1080,1)
                  WinMove('[Class:tSkMainForm]', '', -2500, 0, 287, 1080,1)
               Elseif $TriLoop>0 Then
                  $TriLoop=0               
               Endif
            Elseif $SystemMousePosition[0]>1920 Then
               If $SystemMousePosition[1]<2 Then
                  $TriLoop += 1
                     If $TriLoop = 3 then
                        If WinExists('[Class:MozillaWindowClass]') Then
                           If WinGetState(' - Mozilla Firefox')=23 Then
                           WinSetState(' - Mozilla Firefox','',@SW_MAXIMIZE)
                           Else
                           WinSetState(' - Mozilla Firefox','',@SW_MINIMIZE)
                           Endif
                        Else
                           Run('C:Program Files (x86)Mozilla Firefoxfirefox.exe')
                           While Not(WinExists(' - Mozilla Firefox'))
                           Sleep(25)
                           WEnd
                           $MozillaFirefoxPos=WinGetPos(' - Mozilla Firefox')
                              If Not($MozillaFirefoxPos[0]=1920) And Not($MozillaFirefoxPos[0]=1912) Then
                                 WinSetTrans(' - Mozilla Firefox', '', 0)
                                 WinSetState(' - Mozilla Firefox','',@SW_RESTORE)
                                 WinMove(' - Mozilla Firefox', '', 1912, -8, 1936, 1096)
                                 WinSetState(' - Mozilla Firefox','',@SW_MAXIMIZE)
                                 WinSetTrans(' - Mozilla Firefox', '', 255)
                              Endif                        
                        Endif
                     $TriLoop = 0
                     EndIf
               Elseif $SystemMousePosition[1]>1077 Then
                  $TriLoop += 1
                     If $TriLoop = 3 then
                     Run('"C:Program FilesSandboxieStart.exe" default_browser')
                     $TriLoop = 0
                     EndIf                    
               Elseif $SystemMousePosition[0]<1950    Then
                  $TriLoop += 1
                     If $TriLoop = 3 then
                        If $TaskbarHovered=0 Then
                           $TaskbarHovered=1    
                           $TaskBarLocation=WinGetPos('[Class:Shell_TrayWnd]')
                           WinSetOnTop('[Class:Shell_TrayWnd]', '', 1)
                           Run('"C:Program Files (x86)AutoIt3AutoIt3.exe" "C:Program Files (x86)ScriptsStorageTaskbarTaskbar.au3"')
                           sleep(125)
                           If $TaskBarLocation[0]<0 Then MoveTaskbar('Right')            
                           ControlShow('','', WinGetHandle('[CLASS:Button]'))
                           WinSetTrans('[Class:Shell_TrayWnd]', '', 255)
                        Endif            
                     $TriLoop = 0
                     EndIf
               Elseif $TaskBarHovered=1 And $SystemMousePosition[0]>2185 Then
                  If Not(WinActive('Start menu')) And Not(WinGetState('[Class:TaskListThumbnailWnd]')=7) Then
                     $TaskBarHovered=0
                     ControlHide('','', WinGetHandle('[CLASS:Button]'))
                     WinSetTrans('[Class:Shell_TrayWnd]', '', 0)
                  Endif
               Elseif $SystemMousePosition[0]>3837 Then
                  If $ChatHovered=0 Then
                     $ChatHovered=1
                        If $SystemMousePosition[1]<=360 Then
                           WinMove('[Class:MSBLWindowClass]', '', 3553, 0, 287, 1080,1)
                           WinSetOnTop('[Class:MSBLWindowClass]', '', 1)
                        Elseif $SystemMousePosition[1]>=360 And $SystemMousePosition[1]<=720  Then
                           WinMove('Friends', '', 3553, 0, 287, 1080,1)
                           WinSetOnTop('Friends', '', 1)
                        Elseif $SystemMousePosition[1]>=720 And $SystemMousePosition[1]<=1080 Then
                           WinMove('[Class:tSkMainForm]', '', 3553, 0, 287, 1080,1)
                           WinSetOnTop('[Class:tSkMainForm]', '', 1)
                        Endif    
                  Endif
               Elseif $chathovered=1 And $SystemMousePosition[0]<3550 Then
                  $ChatHovered=0
                  WinMove('Friends', '', 4000, 0, 287, 1080,1)
                  WinMove('[Class:MSBLWindowClass]', '', 4000, 0, 287, 1080,1)
                  WinMove('[Class:tSkMainForm]', '', 4000, 0, 287, 1080,1)
               Elseif $TriLoop>0 Then
                  $TriLoop=0
               Endif
            Else
               If $TaskbarHovered=1 Then
                  $TaskbarHovered=0
                  ControlHide('','', WinGetHandle('[CLASS:Button]'))
                  WinSetTrans('[Class:Shell_TrayWnd]', '', 0)
               Elseif $ChatHovered=1 Then
                  $ChatHovered=0
                  WinMove('Friends', '', 4000, 0, 287, 1080,1)
                  WinMove('[Class:MSBLWindowClass]', '', 4000, 0, 287, 1080,1)
                  WinMove('[Class:tSkMainForm]', '', 4000, 0, 287, 1080,1)
               ElseIf $TriLoop>0 Then
                  $TriLoop=0
               EndIf
            Endif
            #Endregion
         ;EndRegion Tri-Screen

WEnd

Thing is, i am more after a different idea for achieving the same effect. One idea i had was, Hiding lots of GUIs on the screen named, and then getting the application title for where the mouse is.

If $TitleAtMouse > "GUI IDea" then

Select

Case $TitleAtMouse = "GUI IDea Top Left screen"

Do Idea

Case $TitleAtMouse = "GUI IDea Bottom Left screen"

Do Idea

Endselect

Endif

As my script runs if my computer is on, i am always after ways of limiting the amour of Ifs run per loop "for performance". In the idea i listed above, every 250ms it only does 1 IF. and then 15 Cases if the IF is true. Which would be better when my original code which is many IFS per loop even when the end-result might not be true "ie its not over any part of the screen".

So thats why i thought i would open it up to the communality to see if there is a much better way of doing this :)

**Edit dispite my best efforts, every time i paste the code into autoit. It loses all sense of spacing / padding Bear with me, trying this in firefox but dam this broswer is slow.

Edited by IanN1990

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  
Followers 0