AutoHotkey Community

It is currently May 26th, 2012, 9:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: June 15th, 2007, 11:43 pm 
Offline

Joined: September 14th, 2006, 1:47 pm
Posts: 31
Made a little script that stores 9 diffrent mousepositions....

The script overwrites itself and reloads.

store with CTRL+SHIFT+1 to 9
use with CTRL+1 to 9

be sure to name the script file "SaveMousePos.ahk" (or change the code to match it)

Cred to Thalon for the ChangeLine() http://www.autohotkey.com/forum/viewtopic.php?t=6910

Code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
;This script uses relative mouse positions so a window need to be active so it can relate coordinates.....
CoordMode,Mouse,Relative   ;hit the same spot in a window even if the window itself moves
;CoordMode,Mouse,Screen    ;some may like this better
var_button=9


;;;;;;; see to it that u don't move lines 11 through 19.... will end up with duplicate hotkeys

^1::MouseMove,25,102     ; Win=0x370422     Control=Static1     Line Stored=20070616095710
;row will be replaced
;row will be replaced
;row will be replaced
;row will be replaced
^6::MouseMove,186,196     ; Win=0x370422     Control=Button19     Line Stored=20070616095713
;row will be replaced
;row will be replaced
;row will be replaced

;;;;;;;;;;;;;Don't use or delete rows 11 through 19 !!

;Store Mouse positions with CTRL+????+(1_to_9)       Goto stored location with CTRL+(1_to_9)
^+1::
var_button-=1
^+2::
var_button-=1
^+3::
var_button-=1
^+4::
var_button-=1
^+5::
var_button-=1
^+6::
var_button-=1
^+7::
var_button-=1
^+8::
var_button-=1
^+9::
MouseGetPos, Var_X, Var_Y, Var_Win, Var_Control
ScriptLine=^%var_button%::MouseMove,%Var_X%,%Var_Y% %A_Tab% `; Win=%Var_Win% %A_Tab% Control=%Var_Control% %A_Tab% Line Stored=%A_Now%
var_button+=10 ;used to calculate what row to use....
ReplaceLine("SaveMousePos.ahk", var_button, ScriptLine)
Reload

ReplaceLine(File, LineNo, LineData)
{
FileRead, FileContent, %File%
FileDelete, %File%
Loop, parse, FileContent, `n, `r
{
if (A_Index = LineNo) {
LineContent = %LineData%      ;Replace
}
else LineContent = %A_LoopField%

NewFileContent = %NewFileContent%`n%LineContent%
}
StringTrimLeft, NewFileContent, NewFileContent, 1   ;Otherwise first line would be empty
FileAppend, %NewFileContent%, %File%
}


may add a key to toggle between Relative and Screen...

EDIT: made a little more efficient script in the same spirit as the last...
EDIT: mr guests solution is UBER!

/Ricke


Last edited by ricke on June 16th, 2007, 8:55 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2007, 4:03 am 
Code:
Loop, 9
  Hotkey, ^+%A_Index%, NextStatement
Return

NextStatement:
var_button := SubStr(A_ThisHotkey, 0, 1)
....rest of your sub...

you will need to make sure that loop happens before autoexecute section ends.. so put it up above your other hotkeys (like under CoordMode setting...)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2007, 4:16 am 
Code:
CoordMode,Mouse,Relative
Loop, 9
  Hotkey, ^+%A_Index%, StoreSub  ; get mouse pos..
Loop, 9
  Hotkey, ^%A_Index%, UseSub     ; move to prestored pos..
Return

StoreSub:
Num := SubStr(A_ThisHotkey, 0, 1)
MouseGetPos, Var_%Num%_X, Var_%Num%_Y
Return

UseSub:
Num := SubStr(A_ThisHotkey, 0, 1)
MouseMove, Var_%Num%_X, Var_%Num%_Y
Return
:P


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2007, 8:45 am 
Offline

Joined: September 14th, 2006, 1:47 pm
Posts: 31
Pwned!

... damn that was efficient.

those loops blow my mind; didnt know one could loop hotkeys like that =)

tyvm

BTW: It should be possible to place a marker on the screen indicating where the stored locations are....


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2007, 10:20 pm 
Quote:
It should be possible to place a marker on the screen indicating where the stored locations are
Code:
CoordMode, Mouse, screen
Loop, 9
  Hotkey, ~^+%A_Index%, StoreSub  ; get mouse pos..
Loop, 9
  Hotkey, ~^%A_Index%, UseSub     ; move to prestored pos..
SetTimer, ShowGuisTimer, 10       ; watch for ctrl down..
Return 
;#########################################
StoreSub:
  Num := SubStr(A_ThisHotkey, 0, 1)
  MouseGetPos, Pos_%Num%_X, Pos_%Num%_Y
  PosGui()
Return
;----
UseSub:
  Num := SubStr(A_ThisHotkey, 0, 1)
  MouseMove, Pos_%Num%_X, Pos_%Num%_Y, 0
Return
;----
ShowGuisTimer:
  If GetKeyState("Ctrl", "P")
  {
    Loop, 9
    {
      Gui %A_Index%:+LastFoundExist     ; show guis..
        IfWinExist
          Gui, %A_Index%:Show, NoActivate
    }
  }
  Else
  {
    Loop, 9
    {
      Gui %A_Index%:+LastFoundExist     ; hide...
        IfWinExist
          Gui, %A_Index%:Show, +Hide
    }
  }
Return

;// FUNCTION //
PosGui(){                               ; create position guis..
  Global
  Gui, %Num%:Destroy                    ; destroy if previously created
  Gui, %Num%:+ToolWindow -Caption +AlwaysOnTop
  Gui, %Num%:Margin, 0, 0
  Gui, %Num%:Color , 00FF00
  Gui, %Num%:Font, s10 w700
  Gui, %Num%:Add, Text, w15 h15 +Center, %Num%
  Gui, %Num%:Show, % "+Hide NoActivate x" . Pos_%Num%_X - 5 . " y" . Pos_%Num%_Y - 5
}
#z::reload


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2007, 1:41 pm 
Cool =) Nice work


Report this post
Top
  
Reply with quote  
 Post subject: What am I doing wrong?
PostPosted: September 24th, 2008, 7:06 am 
Renamed the text file to SaveMousePos.ahk running it in latest version of autohotkey. The only hotkeys that work are the 2 premade ones in the code (ctrl1 and ctrl6). I can't save (ctrl+shift+#) or return to any other position (ctrl+#) via the hotkeys. I am a noob but if anyone can help me I'd appreciate it!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: stevep and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group