Virtual Skipper Forum Index Virtual Skipper
Virtual Skipper - Official Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Share your Autohotkey favorites
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Virtual Skipper Forum Index -> Hints and Tips
View previous topic :: View next topic  
Author Message
najevi
Capitaine


Joined: 20 Dec 2008
Posts: 248
Location: Gold Coast (Australia)

PostPosted: 06 Jun 2009 9:56    Post subject: Share your Autohotkey favorites Reply with quote

See also: vsk.wikia.com

I am starting this thread for users to share their autohotkey favorites.
Maybe you'll be inspired by some idea you see posted here.

A few simple thread rules:
  1. Please do not quote another user's entire file contents.
  2. If you make revisions to your VSK.ahk file then please edit your original post and don't create a second one.
  3. Be mindful of line-width. It only takes one very long line of code to force the entire thread into scroll-left/scroll-right mode to read the post comments.

If you do not already know about Autohotkey then please visit Northspace for an introduction. That is how I got started.
    In short summary Autohotkey allows frequently used text to be assigned to either a hotkey or to a so-called hotstring.

So please paste the contents of your customized VSK.ahk file in between a pair of CODE tags to ensure that a fixed width font is used to display it.

enjoy!

Code:

; Virtual Skipper AutoHotKey script - - - detailed scripting notes are at vsk.wikia.com - - -

#IfWinActive ahk_class GbxApp ; this caters for VskAC32, Vsk5 and Vsk5Online
#include *i %A_ScriptDir%\vsk-XY.ahk ; user default XY coordinates
; see also: "radar zoom" and "ISAF window" and "AppendCoords()" below
;SetKeyDelay [, Delay, PressDuration, Play] ; not always necessary but can help at times
SetKeyDelay,4,4,0

CR() { ; carriage return =  delay + Enter
  Sleep,50 ; a 50 mS delay seems to make the in-game chat window activate properly
  send,{Enter}
}
CRLF() { ; carriage return plus linefeed =  delay + Enter + delay + Enter
  CR() ;send {Enter} is NOT sufficient the delay is needed for {Enter} to be recognized
  CR()
  Sleep,50
}
ActiveChat() { ; test for an activated chat window text input field
  PixelSearch,,,84,4,84,4,0xFCAC27,0,Fast ; these coordinates (84,4,480,4) are suitable for 1024x768 fullscreen
  return !ErrorLevel
}
Chat(Msg) { ; fast and reliable way of sending a HOTKEY Msg via the chat window
  If !ActiveChat()
    send,{Enter} ; this first ENTER is sent only if the chat window is not already activated
  sendPlay,%Msg% ; perfect for both one-liners and batch lines ... {Enter}%Msg%{Enter} does NOT work
  send,{Enter} ; this inactivates the chat window input box
}
Spam(Msg) { ; used for multiple line chat messages
  Chat(Msg)
  Sleep,50
}
Type(Msg) { ; type (but don't send) a HOTSTRING Msg if (and only if) the chat window is already active
  If ActiveChat()
    sendInput,%Msg% ; don't send Msg if chat window was not already active
}

^1::Chat("Restart coming")
^2::Chat("Restart & go at start minus 1:45")
^3::Chat("no more restarts")
^4::Chat("NPC - no pen cancel race")
^5::Chat("Cancel only wrong pens please")
^6::Chat("this is the start")
^8::Chat("better to $ff0spin and fin$g than to $ff0fit and quit")
^9::Chat("when did $ff0overlap$g begin?")

!a::Chat("testing something ... will you help?")
^b::Chat("ty host  ty fleet    $ff0good-bye")
^c::Chat("cheers")
!c::Chat("$n'getting clear' & 'taking a penalty' are $ff0separate$g actions - ISAF rrs $ff044.2$g")
!d::Chat("$npen. boat may assert ROW while 'getting clear' $ff0but not$g while taking pen. turn")
!e::Chat("$ni had $ff0ROW$g so responsibility to keep clear was $ff0KC$g boat's .. not mine")
^f::Chat("fair winds .. I'll check back later")
^g::Chat("good winds")
^h::Chat("$0ffkeep clear$g .. not yet on $0ffproper course$g")
!h::Chat("$nThat is not hunting. When racing you may $ff0assert$g your right of way")
; i  is bound to toggle interface AND is used as the prefix to all ISAF RRS hotstrings
; j  available
; k  is bound to toggle camera view
^l::Chat("leeward boat .. you must $0ffkeep clear$g")
!l::Chat("last race .. $ff0No more races, sorry!")
^m::Chat("$0ffMARK ROOM$g please .. $ff0I am overlapped inside")
^n::Chat("$0ffno room$g here. you $0ffkeep clear$g.")
^!n::Chat("NPC - no pen cancel race")
; !n  used for Penalty Cancel Request guard  (Alt+N and Alt+P) below
^o::Chat("room to tack $ff0RTT$g please")
!o::Chat("room at $ff0obstruction$g please")
^p::Chat("$ff0proper course$g please")
; !p  used for Penalty Cancel Request guard  (Alt+N and Alt+P) below
; ^!q  used for Sailing Instructions  (Ctrl+Alt+Q) below
^r::Chat("room please")
!r::Chat("check the $ff0replay$g if you wish.  i $ff0was$g fair")
^s::Chat("starboard")
^t::Chat("tacking")
^u::Chat("Unable")
!u::Chat("$nFYI $ff0host$g, I saw the 'Falling back to $ff0TCP$g (from UDP)' alert when joining")
; v  available
^w::Chat("$0ffROOM$g please ... $ff0I have overlap")
; !w  used for Weather Bulletin below
^x::Chat("thanks for racing everyone")
^y::Chat("you tack")
^z::Chat("please help me receive a penalty .. OK?")
!z::Chat("any $ff0eye-witness$g ... speak please")

; Display the Weather Bulletin
;
!w::
KeyWait Alt
send {Escape}
Sleep, 100
send {Down}
Sleep, 50
send {Down}
Sleep, 50
send {Enter}
return

; Penalty Cancel Request guard  (Alt+N and Alt+P)
;
; Guards against accidentally requesting a pen cancel during NPC races
; This requires that "request penalty cancel" be bound to the [ key
;                    Why?    ... because it is not used in chat messages whereas P is used
; ** any key other than [ (e.g. F10) could have been chosen
;
!n:: ; Alt+N to disable Request Penalty Cancel i.e. NPC
NPC := "NPC"
Loop 100
 Tooltip,DISABLED Pen Cancel (%NPC%),150,7
ToolTip
return

!p:: ; Alt+P to enable Request Penalty Cancel i.e. PC
NPC := ""
Loop 100
 Tooltip,ENABLED Pen Cancel (%NPC%PC),150,7
ToolTip
return

$[:: ; edit if "Request Pen Cancel" is bound to a different key than [
If NPC
    return  ; i.e. do nothing, which causes press of [ to be trapped by this script
Send {[}
return

; Sailing Instructions  (Ctrl+Alt+Q)
;
^!q::
KeyWait Control
KeyWait Alt
BlockInput On
Spam("$s$w{Space 3}{=} {=} {=} Sailing Instructions {=} {=} {=}")
Spam("$nFlooding the chat window with $ff04 or more protests$g may get you kicked or banned")
Spam("$nRule 19$m always $ff0respond$g to hail for ROOM at an obstruction")
Spam("$nPenalty Cancel request IS allowed $ff0but PLEASE enforce$g any LEGITIMATE penalty")
Spam("$s$w{Space 15}{=} {=} {=} enjoy{!} {=} {=} {=}")
BlockInput Off
;Spam("Restart is by vote $ff0and only if$g 3min prestart")
;Spam("do NOT ask for a restart ... join the server earlier.")
;Spam("$nRule 2$m $ff0Unfair player$g is banned")
;Spam("$nRule 21$m $ff0keep clear$g while taking penalty turns")
;Spam("$nRule 23.1$m $ff0do not interfere$g if not racing$n e.g. missed mark or start")
;Spam("It is better to $ff0spin and fin$g than to $ff0fit and quit$g")
return

; radar zoom out (F11) and radar zoom in (F12)
; Why? ... 'F11' is just above '-' and 'F12' is just above '+'
; make sure these keys are not bound to any in-game functions
; If game window gets resized then erase old coords by pressing F11 and F12 at the same time
;
F12:: ; radar zoom in (+) takes effect on key release
If RadarPlusX and RadarPlusY {
 KeyWait F12
 Click,%RadarPlusX%,%RadarPlusY%
}else{
 MouseGetPos,RadarPlusX,RadarPlusY
 MsgBox,0,Mouse Coordinates
  ,Assigned`nX: %RadarPlusX%`nY:%RadarPlusY%`nRestoring window ...
  ,2 ; decrease this timeout delay to 0.1 once familiar with process
 WinRestore ahk_class GbxApp
}
return

F11:: ; radar zoom out (-) takes effect on key release
If RadarMinusX and RadarMinusY {
 KeyWait F11
 Click,%RadarMinusX%,%RadarMinusY%
}else{
 MouseGetPos,RadarMinusX,RadarMinusY
 MsgBox,0,Mouse Coordinates
  ,Assigned`nX: %RadarMinusX%`nY:%RadarMinusY%`nRestoring window ...
  ,2 ; decrease this timeout delay to 0.1 once familiar with process
 WinRestore ahk_class GbxApp
}
return

F12 & F11::
F11 & F12:: ; erase X,Y coords for radar zoom buttons
;(press F11 and F12 at the same time and then release) - either order of pressing has same effect
RadarPlusX := ""
RadarPlusY := ""
RadarMinusX := ""
RadarMinusY := ""
MsgBox,0,Mouse Coordinates,
(
Erased X,Y coords for radar buttons
Position mouse cursor over button
and press either F11(-) or F12(+) key

Click OK to restore game window.
)
WinRestore ahk_class GbxApp
return

; ISAF window scroll down (PgDn) and show/hide (PgUp) ... Note: scroll up is _not_ possible
; make sure these keys are not bound to any in-game functions
; If game window gets resized then erase old coords by pressing PgDn and PgUp at the same time
;
PgDn:: ; scroll down ISAF list ... takes effect on key release
If IsafScrollX and IsafScrollY {
 KeyWait PgDn
 Click,%IsafScrollX%,%IsafScrollY%
}else{
 MouseGetPos,IsafScrollX,IsafScrollY
 MsgBox,0,Mouse Coordinates
  ,Assigned`nX: %IsafScrollX%`nY:%IsafScrollY%`nRestoring window ...
  ,2 ; decrease this timeout delay to 0.1 once familiar with process
 WinRestore ahk_class GbxApp
}
return

PgUp:: ; collapse/expand the ISAF list ... takes effect on key release
If IsafX and IsafY {
 KeyWait PgUp
 Click,%IsafX%,%IsafY%
}else{
 MouseGetPos,IsafX,IsafY
 MsgBox,0,Mouse Coordinates
  ,Assigned`nX: %IsafX%`nY:%IsafY%`nRestoring window ...
  ,2 ; decrease this timeout delay to 0.1 once familiar with process
 WinRestore ahk_class GbxApp
}
return

PgUp & PgDn::
PgDn & PgUp:: ; erase X,Y coords for ISAF buttons
;(press PageDn and PageUp at the same time and then release)
IsafScrollX := ""
IsafScrollY := ""
IsafX := ""
IsafY := ""
MsgBox,0,Mouse Coordinates,
(
Erased X,Y coords for ISAF buttons
Position mouse cursor over a button
and press either PageDn or PageUp key

Click OK to restore game window.
)
WinRestore ahk_class GbxApp
return

; ISAF rules (hotstrings not hotkeys)
; - - - Note that _some_ of these rules are not correctly recognized by the VSK umpire - - -
; rule numbering matches the VSK umpire and _not_ the most current ISAF RRS
;
; Your cursor must be within the chat message box for these hotstrings to have the intended effect.
; Otherwise, potentially detrimental key strokes might be sent to the game and upset your race!
;
#Hotstring EndChars -()[]{}:;'"/\,?!`n `t ; remove period (.) from list of so-called ending characters

:*:i10::
Type("$n10 port tack boat shall keep clear of starboard tack boat$m")
return
:*:i11::
Type("$n11 same tack overlapped: windward boat shall keep clear of leeward boat$m")
return
:*:i12::
Type("$n12 on same tack: clear astern boat shall keep clear of clear ahead boat$m")
return
:*:i13::
Type("$n13 keep clear while tacking$m")
return
:*:i14::
Type("$n14 a boat shall avoid contact with another boat$m")
return
:*:i15::
Type("$n15 after $ff0acquiring$g ROW - $ff0initially$g give other boat room to keep clear$m")
return
:*:i16::
Type("$n16.1 ROW boat $ff0changing course$g shall give other boat $ff0room$g to keep clear$m")
return
:*:i17.1::
Type("$n17.1 overlapped $ff0from behind$g: lee boat must not sail above $ff0proper course$g$m")
return
:*:i17.2::
Type("$n17.2 overlapped windward boat must not sail below $ff0proper course$g$m")
return ; ** 17.2 was deleted from ISAF RRS 2009-2012 **  ... but is still enforced by VSK umpire
:*:i18.2a::
i182a:
Type("$n18.2a outside boat shall give mark room $ff0and$g keep clear of a ROW inside boat$m")
return
:*:i18.2b::
i182b:
Type("$n18.2b overlap $ff0before$g zone: original outside gives mark room to inside$m")
return
:*:i18.2c::
i182c:
Type("$n18.2c overlap $ff0after$g zone: astern gives mark room to ahead. HTW cancels$m")
return
:*:i18.2d::
i182d:
Type("$n18.2d$ff0**$g ROW changing course to round need not give room: $ff0No Rule16$g$m")
return
:*:i18.3a::
i183a:
Type("$n18.3a $0ffF$getcher outside $f0fT$gacker: $f0fT$g must allow $0ffF$g to fetch mark$m")
return
:*:i18.3b::
i183b:
Type("$n18.3b $0ffF$getcher inside $f0fT$gacker: $f0fT$g must give mark room $ff0No Rule15$g$m")
return
:*:i18.4::
i184:
Type("$n18.4 inside ROW needs to gybe: do not sail $ff0too far$g from mark$m")
return
:*:i20.1::
Type("$n20.1 Pen 30.1 boat shall keep clear until completely on pre-start side$m")
return
:*:i20.2::
Type("$n20.2 a boat taking a penalty shall keep clear of one that is not$m")
return
:*:i20.3::
Type("$n20.3 a boat moving astern shall keep clear of one that is not$m")
return
:*:i22.1::
Type("$n22.1 $ff0non-racer$g shall not interfere with a $ff0racer$g$m")
return
:*:i22.2::
Type("$n22.2 unless on proper course, do not interfere with boat on another leg or 360-ing$m")
return
:*:i29::
Type("$n29.1 individual recall - dip $ff0behind$g start line is sufficient$m")
return
:*:i30::
Type("$n30.1 OCS (Flag $ff0I$g) within 60sec of start - sail $ff0around$g either end mark$m")
return
:*:i31::
Type("$n31.1 a boat shall not touch a mark$m")
return
:*:i44::
Type("$n44.1 failure to $ff0promptly$g start a penalty turn (within $ff060$g sec)$m")
return
:*:i64::
Type("$n64.1b exonerates COMPELLED boat if due to another boat that FIRST broke a rule$m")
return
:*:ic4.1::
Type("$nC4.1 before preparatory signal remain outside the ends of the start line$m")
return
:*:ic4.2::
Type("$nC4.2 within 2min of prep. signal cross & clear start line from course side$m")
return

::i18:: ; list all rule 18 (Remember - these do _not_ apply at the start line) type: "i18{Space}" to trigger
If ActiveChat() {
   BlockInput On
   Gosub i182a
   CRLF()
   Gosub i182b
   CRLF()
   Gosub i182c
   CRLF()
   Gosub i182d
   CRLF()
   Gosub i183a
   CRLF()
   Gosub i183b
   CRLF()
   Gosub i184
   CR()
   BlockInput off
}   
return

; Other frequently used strings
;
:*:@wiki::vsk.$ff0wikia$g.com$m
:*:@ns::www.$ff0northspace$g.co.uk$m

; - - - Creeping elegance - - -

AppendCoords() { ;Writes the currently used XY coords to the file vsk-XY.ahk (appending to previous lines)
   Global IsafScrollX,IsafScrollY,IsafX,IsafY,RadarPlusX,RadarPlusY,RadarMinusX,RadarMinusY ; crucial
   If IsafScrollX and IsafScrollY
     FileAppend,IsafScrollX := %IsafScrollX%`nIsafScrollY := %IsafScrollY%`n,%A_ScriptDir%\vsk-XY.ahk
   else
     FileAppend,IsafScrollX := ""`nIsafScrollY := ""`n,%A_ScriptDir%\vsk-XY.ahk
   If IsafX and IsafY
     FileAppend,IsafX := %IsafX%`nIsafY := %IsafY%`n,%A_ScriptDir%\vsk-XY.ahk
   else
     FileAppend,IsafX := ""`nIsafY := ""`n,%A_ScriptDir%\vsk-XY.ahk
   If RadarPlusX and RadarPlusY
     FileAppend,RadarPlusX := %RadarPlusX%`nRadarPlusY := %RadarPlusY%`n,%A_ScriptDir%\vsk-XY.ahk
   else
     FileAppend,RadarPlusX := ""`nRadarPlusY := ""`n,%A_ScriptDir%\vsk-XY.ahk
   If RadarMinusX and RadarMinusY
     FileAppend,RadarMinusX := %RadarMinusX%`nRadarMinusY := %RadarMinusY%`n,%A_ScriptDir%\vsk-XY.ahk
   else
     FileAppend,RadarMinusX := ""`nRadarMinusY := ""`n,%A_ScriptDir%\vsk-XY.ahk
}

PgUp & F12::
F12 & PgUp:: ; permanently store X,Y coords for ISAF window buttons and radar zoom buttons
KeyWait F12
KeyWait PgUp
AppendCoords()
MsgBox,0,Mouse Coordinates,
(
Wrote X,Y coords for ISAF window buttons
and radar zoom buttons to the file:
%A_ScriptDir%\vsk-XY.ahk
),3
WinRestore ahk_class GbxApp
return

PgDn & F11::
F11 & PgDn:: ; tidy the file containing custom default X,Y coordinates
KeyWait F11
KeyWait PgDn
MsgBox,260,Mouse Coordinates,
(
Are you sure you want to tidy up the file:
%A_ScriptDir%\vsk-XY.ahk

It will be sent to the recycle bin and then
recreated using the current X,Y coords for
ISAF window buttons and radar zoom buttons.
),3 ; the default response after a timeout is 'No'
WinRestore ahk_class GbxApp
IfMsgBox,Yes
  {
  FileRecycle,%A_ScriptDir%\vsk-XY.ahk ; move the file to the recycle bin
  AppendCoords() ; recreates the file with the current set of coordinates
  }
return

;; - - - Software Change Requests - - -
;;
;; SCR1[DONE] devise a test for an active chat box (e.g. box turns 0xFCAC27 when active)
;;         to qualify the use of
;;         (i) any hotstring - i.e. only allow replacement string when chat box is already ACTIVE
;;
;; SCR2[DONE] devise a test for an active chat box (e.g. box turns 0xFCAC27 when active)
;;         to qualify the use of
;;         (ii) Chat() - i.e. only send a leading {Enter} when chat box is INACTIVE
;;
;; SCR3[DONE] provide for custom user default X,Y coords
;;         as used by hotkey functions {F11,F12,PgUp,PgDn}
;;         provide a suitable hotkey to write these 8 variables
;;         to a file for quick and easy copy and paste into the user's AHK script
;;

; send/sendInput/sendPlay
; This subject is terribly confusing! Idiosyncracies within BOTH ahk AND vsk are probably interacting.
; Trial and error evidence suggests that:
; (i) standalone {Enter} and {Enter}%Msg%{Enter} are only RELIABLY recognized using "send" or "sendInput"
; (ii) send and sendInput are NOT RELIABLE for multi-line messages
; (iii) sendPlay is the most versatile - it is perfect for one-liners as well as multiple line messages
; (iv) HOTSTRINGS must use sendInput and not sendPlay in order for the 'trigger string' to be HIDDEN
; (v) delay + {Enter} (see function CR) is the most reliable way of openning chat and sending a message
;
; The following code examples are NOT reliable
  ;SetKeyDelay,1,1,0 ; 40,40,0 ; optimised for _my_ laptop ... feel free to tweak for your PC
  ;sendInput %Msg% ; perfect for one-liners but not for batch lines
  ;sendEvent %Msg% ; slow - affected by SetKeyDelay values
  ;send {Enter}%Msg%{Enter} ; ENTER _is_ registered but it is slower than sendPlay
  ;sendPlay {Enter}%Msg%{Enter} ; ENTER is never registered ingame
  ;sendInput {Enter}%Msg%{Enter} ; ENTER is never registered ingame

; For scripting help see: www.autohotkey.com
; Please read the QUICK-START TUTORIAL near the top of the help file.
; It explains how to perform common automation tasks such as sending
; keystrokes and mouse clicks.  It also explains more about hotkeys.


Last edited by najevi on 12 Jul 2011 22:32; edited 16 times in total
Back to top
View user's profile Send private message Visit poster's website
CANKnot
Moderator


Joined: 09 Nov 2005
Posts: 1319

PostPosted: 06 Jun 2009 21:26    Post subject: Reply with quote

My two favourite AHK scripts are for:

1: Zoom in/out on the radar with the plus and minus keys, and
2. Switching between red and blue skins for team racing.

I haven't included any code since both scripts rely on screen positions for the mouse clicks. However, these two (and hailing for room to tack) are by far the ones I use the most.
_________________
In theory there is no difference between theory and practice, but in practice there is.
Back to top
View user's profile Send private message
najevi
Capitaine


Joined: 20 Dec 2008
Posts: 248
Location: Gold Coast (Australia)

PostPosted: 06 Jun 2009 22:14    Post subject: Reply with quote

That's a great tip for radar zoom in/out. (please do consider posting your code, it's easy enough for another user to use AutoHotkey's "Window Spy" tool to tweak the coordinates to suit)

I have always wanted a single hotkey for opening and closing the weather report but until today I had not thought of using AutoHotkey to input mouse clicks (or arrow key presses) to achieve that.

EDIT:
  1. I added script for the radar zoom in/out functions at the first post. The user must "teach" the script the mouse coordinates by positioning the cursor and then pressing and releasing either "-" or "=" keys. Thereafter the coordinates are stored in memory. If you change the game window resolution (e.g. toggle between full screen and windowed mode) then simply press both - and = keys at the same time to erase the old coordinates ... then re-teach the new coordinates.

  2. The weather bulletin can now be accessed by pressing Alt+W
    To dismiss the Weather bulletin press Enter.

  3. The ISAF window can now be scrolled using the PgDn key. The user must "teach" the script the mouse coordinates by positioning the cursor and then pressing and releasing the PgDn key. Thereafter the coordinates are stored in memory. If you change the game window resolution (e.g. toggle between full screen and windowed mode) then simply press Alt+PgDn to erase the old coordinates ... then re-teach the new coordinates.
    I don't know how to "scroll up" the ISAF window.
Back to top
View user's profile Send private message Visit poster's website
Skiffie
Capitaine


Joined: 10 Oct 2005
Posts: 251
Location: Brisbane, Australia

PostPosted: 10 Jun 2009 11:21    Post subject: Reply with quote

CANKnot wrote:
My two favourite AHK scripts are for:

1: Zoom in/out on the radar with the plus and minus keys, and
2. Switching between red and blue skins for team racing.

I haven't included any code since both scripts rely on screen positions for the mouse clicks. However, these two (and hailing for room to tack) are by far the ones I use the most.


How do you do that Keith?
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
najevi
Capitaine


Joined: 20 Dec 2008
Posts: 248
Location: Gold Coast (Australia)

PostPosted: 11 Jun 2009 1:57    Post subject: Reply with quote

I am not so sure this forum is a good place to be adding script ideas.
The same information has been copied to vsk.wikia.com see the AutoHotkey article there.
A wiki gives much greater flexibility for annotating explanations and illustrating concepts with uploaded images. Revision history is also preserved at a wiki.

Skiffie for an example of how to assign the red/blue team switch to a hotkey see the Alt+W (show weather bulletin) script above. The fundamental steps for navigating the Esc menu are the same.
Back to top
View user's profile Send private message Visit poster's website
hula
Capitaine


Joined: 06 Oct 2005
Posts: 152
Location: Mestrino PD Italy

PostPosted: 11 Jun 2009 2:01    Post subject: Reply with quote

I used AutoScriptWriter (recorder) for do that and capture the position of mouse in my screeen (1440*900).... I use the 'ù' keys (italian keyboard) because is more simply and under the '+' key Clin d'oeil

I add my "room to tack" with screenshot instruction.


Quote:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The unmodified '+' keys causes the radar zoom in
;NumpadAdd::
+::
MouseClick, left, 340, 811
Sleep, 100
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The 'ù' keys zoom out
ù::
;NumpadSub::
MouseClick, left, 318, 842
Sleep, 100
return

;;;;;;;;;;;;;;;;;
;The 'PgDn' key for scroll the ISAF panel
PgDn::
MouseClick, left, 1308, 12
Sleep, 100

;;;;;;;;;;;;;;;;;;
; hail room to tack with screenshot at 0 time and after 8 sec
^t::
Send {Enter} $6f0Room To Tack! {Enter}
Send {F10}
Sleep, 8000
Send {F10}
return

_________________
aloha

Claudio - hula
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Skiffie
Capitaine


Joined: 10 Oct 2005
Posts: 251
Location: Brisbane, Australia

PostPosted: 15 Jun 2009 9:42    Post subject: Reply with quote

najevi wrote:
I am not so sure this forum is a good place to be adding script ideas.
The same information has been copied to vsk.wikia.com see the AutoHotkey article there.
A wiki gives much greater flexibility for annotating explanations and illustrating concepts with uploaded images. Revision history is also preserved at a wiki.

Skiffie for an example of how to assign the red/blue team switch to a hotkey see the Alt+W (show weather bulletin) script above. The fundamental steps for navigating the Esc menu are the same.


Thanks, I would have guessed that it was to change teams as opposed to team skins as per CANKnot's original post - perhaps a typo there?

I like your ISAF strings as well! Cool Cool However!

Quote:
^w::send {Enter} $0ffwater$g please ... $ff0I have overlap {Enter}


Wouldn't it be more appropriate to hail "room" instead of "water" in this instance? I can only assume you are invoking R19(b) (09-12 RRS)?
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
najevi
Capitaine


Joined: 20 Dec 2008
Posts: 248
Location: Gold Coast (Australia)

PostPosted: 15 Jun 2009 11:43    Post subject: Reply with quote

I've often wondered about "room" vs "water" vs "land"

There's already "room to tack" (r20.1) and "mark room" (r18.2 & r18.3) and so I chose "Water" for r19 (as opposed to, say RTP "room to pass") only to remove any possible misunderstanding of intent.

I'm not sure it matters but then ... I remember reading about a protest that was denied in a Sydney-Hobart race because the word "protest" has not hailed!

Maybe "room" is the best after all.
Back to top
View user's profile Send private message Visit poster's website
jampit
Matelot


Joined: 11 Sep 2006
Posts: 81
Location: Northern Ireland

PostPosted: 15 Jun 2009 15:41    Post subject: Reply with quote

Certainly under the new (2009-2012) rules 'Room' is the correct call. I think some novices were confused by 'Water'.
You probably need a key for 'No overlap' to stop some chancers diving in too late. That usually causes problems for the right of way boat as well.

Some good ideas here! Tr?s content
Back to top
View user's profile Send private message
CANKnot
Moderator


Joined: 09 Nov 2005
Posts: 1319

PostPosted: 28 Jun 2009 10:25    Post subject: Reply with quote

Quote:
How do you do that Keith?

Najevi was correct, I recorded changing skins with the macro recorder and then used the recorded coordinates in my own script (included below).

This is part of my Magnum Opus of AHK scripts. It will require some tweaking to work for other people but I've included a couple of the more interesting features:

- mouse x/y coordinates are scaled based on the screen dimensions. This means the script works even if the user toggles between full screen and windowed mode or resizes the VSK window. Note: it takes some tweaking to get the coordinates right based on your screen resolution. The coordinates here won't work out of the box for most people.
- the script shows how to register a "hook" with Windows to be notified of Window's events (resize in this case).
- the script opens a separate window to display debug messages, key mappings etc. This is really handy in a dual monitor set up.
- A few handy hot keys for displaying the mouse coordinates: Control+? displays the mouse coordinates in the chat window and Control+Shift+? displays a Windows dialog with the current mouse position.

Code:

; Window title must start with the specified text
SetTitleMatchMode, 1 
SetTitleMatchMode, Slow
DetectHiddenText, On
         
;; Handle to the VSK Window. Used to detect WM_SIZE
;; events in the VSK window.
hVskWindow = 0

;; Change these to the screen resolution used when recording
;; the macros. Used when rescaling to other window sizes.
DESIGN_RES_X = 1400.0
DESIGN_RES_Y = 1050.0

;; Window scale factor for the current VSK window
;; size.  A value of 0 means the scale needs to
;; be recalculated.
scale_x := 0.0
scale_y := 0.0

;; X,Y coordinates of the zoom in/out buttons on
;; the screen.
zoomOutX := 330
zoomOutY := 947
zoomInX := 309
zoomInY := 983

CreateDebugWindow()

return   ; end of the auto-execute section

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Send text to the chat window
Chat(text)
{
   Send {enter}%text%
   Sleep 100
   Send {enter}
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Clicks the left mouse button at the specified
;; screen position. The "Speed" is how fast the mouse
;; moves to the specified position.  Possible values range
;; from 0 (fastest) to 100 (slowest). The AHK default is 2,
;; which seems to be too fast for VSK. If mouse clicks
;; are not registering correctly you many need to ajust
;; the default value.
;;
;; How long it takes before calling this and the mouse
;; actually being clicked depends on how far away the
;; mouse pointer is from where we want to click it.

MyClick(X, Y, Speed=5)
{
   global scale_x, scale_y
   if not scale_x
   {
      ;; The window has been resized since
      ;; the last mouse click.
      Rescale()
   }
   ;; Scale the mouse coordinates for the current
   ;; window resolution.
   X *= scale_x
   Y *= scale_y
   ;; DebugMessage("X=" X " Y:" Y)
   MouseMove %X%, %Y%, %Speed%
   Click
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Same as the above only with a short pause after.

SlowClick(X, Y, Speed=5, Delay=1250)
{
   MyClick(X, Y, Speed)
   Sleep %Delay%
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Select the red and blue skins for the RC44. The only
;; difference between selecting the skins is the location
;; of the skin on the screen. This works because all
;; the RC44 skins I have fit on one page. If you have
;; more skins or more boats the SelectSkin(X, Y) method
;; will need changing.

SelectRedSkin()
{
   
        SelectSkin(1042, 893) ;; 1073,888
}

SelectBlueSkin()
{
   SelectSkin(890, 880) ;; 915, 888
}

SelectSkin(X, Y)
{
   ; Wait for the control key to be released.
   ; Change this if a different modifier key
   ; is used. We need to make sure all keys
   ; have been released before blocking input
   ; or problems may result.
   KeyWait Control

   ; Ignore user input while we change skins.
   BlockInput On

   ; Generate all the mouse clicks. Longer pauses
   ; may need to be introduced depending on
   ; CPU speed.
        Back()
        Back()
        SlowClick(606, 656)  ; Settings
        SlowClick(112, 314)  ; Boats
        SlowClick(105, 376)  ; RC44
        SlowClick(X, Y)      ; Skin
        Back()
        Back()
        SlowClick(704, 444)  ; Multiplayer
        SlowClick(704, 383)  ; Internet
   ; Accept user input again.
   BlockInput Off
}

;; Click on the Back button.
Back()
{
   SlowClick(130, 965)
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Recalculate the window scaling factors for the
;; current screen resolution and window size.
Rescale()
{
   global DESIGN_RES_X, DESIGN_RES_Y
   global scale_x, scale_y, hVskWindow
   if not hVskWindow
   {
      RegisterHook()
   }
   WinGetPos winX, winY, W, H, VskAC32
   scale_x := W / DESIGN_RES_X
   scale_y := H / DESIGN_RES_Y
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Register an event hook with Windows so we are notified when
;; the VSK window is resized.
RegisterHook()
{
   global hVskWindow
   ; Get the process ID of the VSK window.
   ;WinGet, hVskWindow, PID, VskAC32
   MouseGetPos, X, Y, hVskWindow
   if not hVskWindow
   {
      ; TODO: We should likely do an ExitApp here.
      MsgBox,8192,"Hook Error", "Unable to register the resize hook"
      return
   }
      HookProcAdr := RegisterCallback("ResizeHook")
   DllCall("CoInitialize", "uint", 0)
   return DllCall("SetWinEventHook", "uint", 0x0A, "uint", 0x0B, "uint", 0, "uint", HookProcAdr, "uint", hVskWindow, "uint", 0, "uint", 0)
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Called by Windows when the VSK window is resized.  Windows will call this twice per
;; resize, once when the user starts (event 10) and again when the user is finished
;; resizing the window (event 11). We only pay attention to event 11.
ResizeHook(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime )
{   
   if event = 11
   {
      ; The VSK window was resized.
      Rescale()
   }
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Display a simple message on the debug window.
DebugMessage(message)
{
   global hMessage
   GuiControl, Text, hMessage, %message%
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Create a window to display debugging information. This is most useful in
;; dual monitor setups.
CreateDebugWindow()
{
   global hMessage
   Gui, Font, s12, Verdana
   Gui, Add, Text, VhMessage W300, No message..........................
   Gui, Add, Text, , F1 : "Room to tack"
   Gui, Add, Text, , F2 : "You Tack"
   Gui, Add, Text, , F3 : "Room"
   Gui, Add, Text, , F4 : "Starboard!"
   Gui, Add, Text, , SHIFT+F4 : "No room"
   Gui, +Resize -SysMenu
   Gui, Show, W400, Debug Window
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Hotkey definitions begin here
;;

;; This may need to be changed for other version of
;; VSK.  Use the AutoHotKey Windos Spy utility to
;; find the Windows's name for the VSK window.
#IfWinActive VskAC32

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Catch ALT+ENTER keystroke so we can update the
;; window scaling if the user toggles between
;; fullscreen and windowed modes with them
!Enter::
scale_x := 0  ; this will force a re-scale
Send !{enter} ; pass the ALT+ENTER along
;; Using ALT+ENTER to toggle the window size will also
;; leave the chat window active, this de-activates it.
Sleep 100
Send {enter}
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Control-R selects the RC44 red skin
^R::
SelectRedSkin()
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Control-B selects the RC44 blue skin
^B::
SelectBlueSkin()
return

 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Control-? will print a message in chat window giving
;; the current mouse location. Use this hot key to
;; determine the mouse location in the VSK window when
;; creating commands that need to issue mouse events.
;;
^/::
MouseGetPos, xpos, ypos
Chat("X=" xpos " Y=" ypos).
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Control+Shift+? displays the mouse position in a
;; pop-up dialog.  This will temporarily minimize VSK.
^+/::
MouseGetPos, X, Y
MsgBox,0,Mouse Coordinates
  ,Assigned`nX: %X%`nY:%Y%`nRestoring window ...
  ,2
WinRestore ahk_class GbxApp
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Simulate a mouse wheel with CTRL+UP and CTRL+DOWN
;; This may not work if your mouse does not actually
;; have a wheel on it.
^up::MouseClick, WheelUp, , , 1
^down::MouseClick, WheelDown, , , 1

-::
if zoomInX
{
   MyClick(zoomInX, zoomInY)
}
else
{
   MouseGetPos,zoomInX,zoomInY
   DebugMessage("X=" zoomInX " Y=" zoomInY)
   Click
}
return

=::
if zoomOutX
{
   MyClick(zoomOutX, zoomOutY)
}
else
{
   MouseGetPos,zoomOutX,zoomOutY
   DebugMessage("X=" zoomOutX " Y=" zoomOutY)
   Click
}
return

;; Common hails

F1:: Chat("Room to tack (R19)")
F2:: Chat("You tack")
F3:: Chat("Mark room please")
^F3:: Chat("No overlapped at the zone.")
F4:: Chat("Starboard!")
^F4:: Chat("I need some help back here.")

_________________
In theory there is no difference between theory and practice, but in practice there is.
Back to top
View user's profile Send private message
Camster
Moderator


Joined: 09 Dec 2005
Posts: 1437
Location: Scotland

PostPosted: 28 Jun 2009 21:26    Post subject: Reply with quote

Thanks for that Keith, Najevi & all and there is a lot of interesting stuff in this thread for those of us who dabble in Autohotkey. In particular I had not realised the need to slow down the mouse movement and have been finding some of my scripts a little unreliable. So I have put a line at the top of my script to change the default speed to 5 & that seems to have fixed all the scripts in one go - thanks!

I have various chat messages, & use the mouse to zoom out the radar, tack the boat, pin the sails in tight with manual trim, open the weather window & open the kick list.
Suggestions I have adopted from Chameleon include a key delay setting and an arrangement to make the hotkeys only work when VSK is the active window. So my header now reads...


#IfWinActive VskAC32

SetKeyDelay 4,4
SetDefaultMouseSpeed, 5

_________________
Sandy
Back to top
View user's profile Send private message Visit poster's website
CANKnot
Moderator


Joined: 09 Nov 2005
Posts: 1319

PostPosted: 01 Jul 2009 1:43    Post subject: Reply with quote

You can also use if #IfWinActive in several places in the script to target different hotkeys to different windows. For example, when VSK is active F1 hails for room to tack, but if the ITBYC chat room is active F1 tells TC to pick new teams.

Code:

#IfWinActive VskAC32

F1:: Chat("Room to tack (R.19)")
^r:: SelectRedSkin()
^b:: SelectBlueSkin()

...

#IfWinActive, IRC - Theo's IRC Server

F1:: Send TC pick teams{enter}
^r:: Send TC red won race{space}
^b:: Send TC blue won race{space}
 
...

_________________
In theory there is no difference between theory and practice, but in practice there is.
Back to top
View user's profile Send private message
najevi
Capitaine


Joined: 20 Dec 2008
Posts: 248
Location: Gold Coast (Australia)

PostPosted: 21 Jul 2009 19:38    Post subject: errata - ISAF RRS hotstrings made consistent with 32AC/VSK5 Reply with quote

If anyone copied my ISAF RRS hotstrings from the code block in the OP then I apologize for any confusion they may have caused, notably for rules 17 through 23.2

I'd given contemporary rule numbers (RRS 2009-2012) instead of rule numbers that are consistent with the VSK5/32AC auto-umpire (RRS 2005-2008)

That error was corrected just now.
Back to top
View user's profile Send private message Visit poster's website
najevi
Capitaine


Joined: 20 Dec 2008
Posts: 248
Location: Gold Coast (Australia)

PostPosted: 13 Sep 2009 4:21    Post subject: A handy user function Reply with quote

I had noticed that some of my AHK generated chat messages were being truncated and decided to convert all messages to use the sendInput built-in function rather than the send function. The following user function nicely takes care of the handling of the Enter keystroke without bloating the code at each and every keyboard shortcut definition line.

Code:

Chat(Msg) {
  SetKeyDelay,40,40,0
  send {Enter}
  sendInput %Msg%
  send {Enter}
  SetKeyDelay,gDelay,gPress,gPlay
}


gDelay, gPress and gPlay are global variables (see post #1) so that last line is simply restoring the global defaults to whatever they were before the function was called.
Back to top
View user's profile Send private message Visit poster's website
Camster
Moderator


Joined: 09 Dec 2005
Posts: 1437
Location: Scotland

PostPosted: 13 Sep 2009 9:11    Post subject: Reply with quote

Thanks Najevi - I hadn't worked any of that stuff out and I'll give it a try for my multiple-line host rules, which do get trunkated at times.
_________________
Sandy
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Virtual Skipper Forum Index -> Hints and Tips All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

Anti Bot Question MOD - phpBB MOD against Spam Bots
Blocked registrations / posts: 142140 / 0