[Scripting] Zoom to Center

Next
 From:  Umdee (BFEDACK)
7061.1 
Let's say you want to zoom to the center of the viewport as opposed to the current method that zooms to the mouse cursor. This can be achieved by binding a couple keys to scripts in MoI and using AutoHotkey.

In MoI, create the following keyboard shortcuts:
code:
PageDown=script: var scale = 0.20; var vp = moi.ui.getActiveViewport(); if (vp != null) vp.Zoom(1 + scale);
PageUp=script: var scale = 0.20; var vp = moi.ui.getActiveViewport(); if (vp != null) vp.Zoom(1 - scale);


Create the following AutoHotkey script:
code:
#IfWinActive, ahk_class MoiMainWindow

; Zoom to Center
^MButton::
CoordMode, Mouse, Screen
threshold := 20
MouseGetPos, co_x, co_y
while GetKeyState("MButton", "P")
{
    MouseGetPos, mouse_x, mouse_y
    abs_offset := Abs(co_y - mouse_y)
    offset_sign := (co_y - mouse_y < 0) ? -1 : 1

    ; Zoom events only occur when the magnitude of the offset is at least as
    ; large as the threshold distance.
    if (abs_offset>= threshold)
    {
        ; Determine how many threshold distances fit within the offset.
        multiple := abs_offset // threshold

        ; Mouse moved down.
        if (offset_sign = -1)
        {
            Send {PgUp %multiple%} ; Zoom in.
        }

        ; Mouse moved up.
        else
        {
            Send {PgDn %multiple%} ; Zoom out.
        }

        ; Update the stored y-coordinate.
        co_y := mouse_y
    }
    Sleep 10
}
return


After executing the AutoHotkey script, you may now zoom to the center of the viewport using Ctrl+MMB. You can change the MoI "scale" and AutoHotkey "threshold" variables to adjust the sensitivity and smoothness of zooming.

EDITED: 23 Nov 2014 by BFEDACK

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7061.2 In reply to 7061.1 
So where do these autohotkey scripts go?

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Umdee (BFEDACK)
7061.3 In reply to 7061.2 
Save the script as a file ending in the "ahk" extension, such as "zoom_to_center.ahk". With AutoHotkey installed (http://www.autohotkey.com), double-click the script file to run it. You can right-click and compile the script into an independent executable, allowing it to be used on a machine that does not have AutoHotkey installed.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All