MousePrecise.ahk for Pixel-Level Cursor Control

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jackdunning
Posts: 126
Joined: 01 Aug 2016, 18:17
Contact:

MousePrecise.ahk for Pixel-Level Cursor Control

30 Sep 2019, 17:03

I've always found using a mouse to accurately capture art a little tricky. Whenever I released a depressed
left-mouse button, the cursor always seems to jump a pixel or two. This causes a serious problem in some
graphic operations such as clipping odd shapes from any artwork. In the course of working on the book
AutoHotkey Hotkey Techniques, I wrote a script I call MousePrecise.ahk which takes advantage of keyboard
scan codes to turn the numeric keypad into a pixel-level cursor operator.

MousePrecise.ahk script Discussed in a series of blogs about Hotkeys at Jack's AutoHotkey Blog and featured in the book AutoHotkey Hotkey Techniques.

Image

The MousePrecise.ahk script converts the numeric keypad into a micro mover for the mouse cursor—one pixel
at a time. This AutoHotkey script creates a graphics tool for precisely positioning the mouse cursor.
GroupAdd command adds graphic programs to the group of active windows with functioning MousePrecise Hotkeys.
(Note: The Snipping Tool requires three different windows in the group.)

October 8, 2019 — I've made the changes to embed the Mouse2.ico image in the script rather than providing it separately per suggestion made by @guest3456.

March 1, 2020 — Added a 16-pixel jump from top-left to bottom-right to the center keypad button (5) for cropping square images in the same increments as icons (16x16, 32x32, 48x48, etc). Use Shift+NumPad5 to reverse direction.

Code: Select all

SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
; FileInstall, Mouse2.ico, Mouse2.ico  ; replaced with Create_Mouse2_ico() function

; add to auto-execute section of script
GroupAdd, Graphics, ahk_class Microsoft-Windows-Tablet-SnipperToolbar
GroupAdd, Graphics, ahk_class Microsoft-Windows-Tablet-SnipperCaptureForm
GroupAdd, Graphics, ahk_class Microsoft-Windows-Tablet-SnipperEditor
GroupAdd, Graphics, ahk_class IrfanView
GroupAdd, Graphics, ahk_class MSPaintApp


Hotkey, NumpadEnter, off
Menu, tray, add, Add Window Class (CTRL+NumpadDel), AddClass
Menu, tray, add, Reload, Reload

; Changed to embedded ICO file
; Menu, tray, Icon, Mouse2.ico
Menu, tray, Icon, % "HBITMAP:*" . Create_Mouse2_ico()

		
; Add the following directives and Hotkeys toward the end of the script

#IfWinActive ahk_group Graphics  
    
!up::MouseMove, 0, -1, 0, R  ; Win+UpArrow hotkey => Move cursor upward
!Down::MouseMove, 0, 1, 0, R  ; Win+DownArrow => Move cursor downward
!Left::MouseMove, -1, 0, 0, R  ; Win+LeftArrow => Move cursor to the left
!Right::MouseMove, 1, 0, 0, R  ; Win+RightArrow => Move cursor to the right
;Numpad0::Send % (toggle := !toggle) ? "{LButton Down}" : "{LButton Up}"  ; Replaced with Scan Code

;SC052::Send % (toggle := !toggle) ? "{LButton Down}" : "{LButton Up}"    ; Replaced with "If" conditional to add more features

; There are two forms of the SC052 Hotkey. The first uses If conditional statements to embedded additional commands.
; The second form (currently active) uses functions to embed the on and off command, plus the ternary operator in the Hotkey.
; The second form makes the script more modular (one Hotkey and two functions) while making the function available
; elsewhere in the script—if needed.


/*         
SC052::                ; This is the If conditional form of the Hotkey
   if  (toggle := !toggle)
    {
	  Hotkey, NumpadEnter, on
	  Send {LButton Down}
	  Tooltip, Left Button Down`rNumpadEnter to cancel, 20,20
	}
    else
	{	   
	  Hotkey, NumpadEnter, off
	  Send {LButton Up}
	  Tooltip
	}
Return
*/

SC052::% (toggle := !toggle) ? toggleon() : toggleoff()  ; This form of the Hotkey using functions and the ternary
toggleon()
    {
	  Hotkey, NumpadEnter, on
	  Send {LButton Down}
	  Tooltip, Left Button Down`rNumpadEnter to cancel, 20,20
	}

toggleoff()
	{	   
	  Hotkey, NumpadEnter, off
	  Send {LButton Up}
	  Tooltip
	}
	
; Hardwire mouse cursor movement in eight directions one pixel at a times

SC04F::MouseMove, -1, 1, 0, R  ; Numpad1 key down left
SC050::MouseMove, 0, 1, 0, R   ; Numpad2 key down
SC051::MouseMove, 1, 1, 0, R   ; Numpad3 key down right
SC04B::MouseMove, -1, 0, 0, R  ; Numpad4 key left
SC04C::MouseMove, 16, 16, 0, R ; Numpad5 key 16px square
+SC04C::MouseMove, -16, -16, 0, R ; Numpad5 key 16px square reversed
SC04D::MouseMove, 1, 0, 0, R   ; Numpad6 key right
SC047::MouseMove, -1, -1, 0, R ; Numpad7 key up left
SC048::MouseMove, 0, -1, 0, R  ; Numpad8 key up
SC049::MouseMove, 1, -1, 0, R  ; Numpad9 key up right

^SC050::MouseMove, -1, 2, 0, R ; Sample code for adding another angle  206.6°
^SC048::MouseMove, 1, -2, 0, R ; Sample code for adding another angle   26.6°
^SC04D::MouseMove, 7, -4, 0, R ; Sample code for adding another angle   ~60 °

#If toggle and WinActive("ahk_group Graphics") ;disable the left mouse button
 
LButton::Return

#If



NumpadEnter::   ; Escape Hotkey
  Tooltip              ; turn Tooltip off
  toggle = 0           ; set toogle to off
  Send {LButton Up}    ; release LButton
Return


^SC053::   ;Hotkey CTRL+NumpadDel to add window class to group
  WinGetTitle, title , A
  WinGetClass, class, A
  ; Ignore certain classes of windows — This portion stolen from Jim S.
  ; Progman = Desktop; DV2ControlHost = Start Menu; Shell_TrayWnd = Taskbar
If class in Progman,DV2ControlHost,Shell_TrayWnd,Windows.UI.Core.CoreWindow,WorkerW,MultitaskingViewFrame
  Return
Else
  {
  GroupAdd, Graphics, ahk_class %class%
  RegExMatch(title,"-\s(.*)",ProgName)
  MsgBox, % ProgName1 . " temporarily`radded to MousePrecise group."
  }
Return

Reload:
  Reload
Return

AddClass:
  SendInput, !{Esc}
  GoSub, ^SC053
Return

; add this func at bottom:
; ##################################################################################
; # This #Include file was generated by Image2Include.ahk, you must not change it! #
; #
; # https://autohotkey.com/board/topic/93292-image2include-include-images-in-your-scripts/
; #
; ##################################################################################
Create_Mouse2_ico(NewHandle := False) {
Static hBitmap := 0
If (NewHandle)
   hBitmap := 0
If (hBitmap)
   Return hBitmap
VarSetCapacity(B64, 4352 << !!A_IsUnicode)
B64 := "AAABAAEAICAAAAEAGACoDAAAFgAAACgAAAAgAAAAQAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
If !DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", 0, "UInt", 0x01, "Ptr", 0, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
   Return False
VarSetCapacity(Dec, DecLen, 0)
If !DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", 0, "UInt", 0x01, "Ptr", &Dec, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
   Return False
; Bitmap creation adopted from "How to convert Image data (JPEG/PNG/GIF) to hBITMAP?" by SKAN
; -> http://www.autohotkey.com/board/topic/21213-how-to-convert-image-data-jpegpnggif-to-hbitmap/?p=139257
hData := DllCall("Kernel32.dll\GlobalAlloc", "UInt", 2, "UPtr", DecLen, "UPtr")
pData := DllCall("Kernel32.dll\GlobalLock", "Ptr", hData, "UPtr")
DllCall("Kernel32.dll\RtlMoveMemory", "Ptr", pData, "Ptr", &Dec, "UPtr", DecLen)
DllCall("Kernel32.dll\GlobalUnlock", "Ptr", hData)
DllCall("Ole32.dll\CreateStreamOnHGlobal", "Ptr", hData, "Int", True, "PtrP", pStream)
hGdip := DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll", "UPtr")
VarSetCapacity(SI, 16, 0), NumPut(1, SI, 0, "UChar")
DllCall("Gdiplus.dll\GdiplusStartup", "PtrP", pToken, "Ptr", &SI, "Ptr", 0)
DllCall("Gdiplus.dll\GdipCreateBitmapFromStream",  "Ptr", pStream, "PtrP", pBitmap)
DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "PtrP", hBitmap, "UInt", 0)
DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", pBitmap)
DllCall("Gdiplus.dll\GdiplusShutdown", "Ptr", pToken)
DllCall("Kernel32.dll\FreeLibrary", "Ptr", hGdip)
DllCall(NumGet(NumGet(pStream + 0, 0, "UPtr") + (A_PtrSize * 2), 0, "UPtr"), "Ptr", pStream)
Return hBitmap
}
ALT+arrow key moves mouse one pixel in the direction of the arrow key for precise alignment.

Uses scan Codes for the numeric pad to map mouse cursor movement in eight directions
bypassing the NumLock key.

Numpad0 toggles left mouse button up and down.

Since the left mouse button is disabled while LButton is toggled down, NumpadEnter is an escape
key for those times when a graphic window accidentally goes inactive while the LButton
is toggled down.

To temporarily activate the Hotkey group for any window to use CTRL+NumpadDel key.
This Hotkey adds the currently active window's class to the Graphics group. To permanently
add the program's class, insert the GroupAdd command in the appropriate spot.

If for some reason the Hotkeys stop working, right-click on the system tray icon and select Reload.

To temporarily add a window to the group right-click on the system tray icon and select Add Window Class.

The GroupAdd command isolates the Hotkeys' availability to the graphics programs included in the group. As a summary script, it uses a number of commands and directives considered best practices for optimizing Hotkeys.

Forced expressions, toggles, and the ternary operator demonstrate how more power and flexibility can be added to almost any AutoHotkey command.
Last edited by jackdunning on 01 Mar 2020, 08:54, edited 2 times in total.
User avatar
jackdunning
Posts: 126
Joined: 01 Aug 2016, 18:17
Contact:

Re: MousePrecise.ahk for Pixel-Level Cursor Control

05 Oct 2019, 14:16

I actually use this MousePrecise.ahk script on a regular basis. (Many of my other scripts I post for purely educational purposes.)

Although a short script, it has saved me from futile attempts at accurately cropping an image with a mouse—whether square or irregular.
If an image has one pixel of separation, you can precisely crop it in any graphics program.

Image

However, you only need this capability if you must move the mouse cursor one pixel at a time (in one of eight directions) while holding down the left mouse button.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: MousePrecise.ahk for Pixel-Level Cursor Control

05 Oct 2019, 23:48

nice script.

quick change if you don't want external ico file dependencies and can ensure at least ahk v1.1.27:
jackdunning wrote:
30 Sep 2019, 17:03

Code: Select all


; remove:
; FileInstall, Mouse2.ico, Mouse2.ico

; change:
; Menu, tray, Icon, Mouse2.ico
; to:
Menu, tray, Icon, % "HBITMAP:*" . Create_Mouse2_ico()

; add this func at bottom:
; ##################################################################################
; # This #Include file was generated by Image2Include.ahk, you must not change it! #
; #
; # https://autohotkey.com/board/topic/93292-image2include-include-images-in-your-scripts/
; #
; ##################################################################################
Create_Mouse2_ico(NewHandle := False) {
Static hBitmap := 0
If (NewHandle)
   hBitmap := 0
If (hBitmap)
   Return hBitmap
VarSetCapacity(B64, 4352 << !!A_IsUnicode)
B64 := "AAABAAEAICAAAAEAGACoDAAAFgAAACgAAAAgAAAAQAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDR0dGFhppbWmtBQVQqKj4eHjkhKToqKj4bGzQeHjkbGzQjKT4/R1tma35+h5B7fouwt73w8PDw8PCpvONbdNFBa85LddHk7+/w8PDw8PDw8PDw8PDw8PDw8PDw8PDb2+AsMVIrL1I3Q2ZEWH5XaZNfdZ9TcKNKY5pFYZc+VH5AUnJTXXtfZn1SWm9MVmhFSFVgZ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Dw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
If !DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", 0, "UInt", 0x01, "Ptr", 0, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
   Return False
VarSetCapacity(Dec, DecLen, 0)
If !DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", 0, "UInt", 0x01, "Ptr", &Dec, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
   Return False
; Bitmap creation adopted from "How to convert Image data (JPEG/PNG/GIF) to hBITMAP?" by SKAN
; -> http://www.autohotkey.com/board/topic/21213-how-to-convert-image-data-jpegpnggif-to-hbitmap/?p=139257
hData := DllCall("Kernel32.dll\GlobalAlloc", "UInt", 2, "UPtr", DecLen, "UPtr")
pData := DllCall("Kernel32.dll\GlobalLock", "Ptr", hData, "UPtr")
DllCall("Kernel32.dll\RtlMoveMemory", "Ptr", pData, "Ptr", &Dec, "UPtr", DecLen)
DllCall("Kernel32.dll\GlobalUnlock", "Ptr", hData)
DllCall("Ole32.dll\CreateStreamOnHGlobal", "Ptr", hData, "Int", True, "PtrP", pStream)
hGdip := DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll", "UPtr")
VarSetCapacity(SI, 16, 0), NumPut(1, SI, 0, "UChar")
DllCall("Gdiplus.dll\GdiplusStartup", "PtrP", pToken, "Ptr", &SI, "Ptr", 0)
DllCall("Gdiplus.dll\GdipCreateBitmapFromStream",  "Ptr", pStream, "PtrP", pBitmap)
DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "PtrP", hBitmap, "UInt", 0)
DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", pBitmap)
DllCall("Gdiplus.dll\GdiplusShutdown", "Ptr", pToken)
DllCall("Kernel32.dll\FreeLibrary", "Ptr", hGdip)
DllCall(NumGet(NumGet(pStream + 0, 0, "UPtr") + (A_PtrSize * 2), 0, "UPtr"), "Ptr", pStream)
Return hBitmap
}


User avatar
jackdunning
Posts: 126
Joined: 01 Aug 2016, 18:17
Contact:

Re: MousePrecise.ahk for Pixel-Level Cursor Control

06 Oct 2019, 13:34

Wow @guest3456! That's pretty impressive. I'll have to blog about that one.
User avatar
jackdunning
Posts: 126
Joined: 01 Aug 2016, 18:17
Contact:

Re: MousePrecise.ahk for Pixel-Level Cursor Control

08 Oct 2019, 16:12

The original version of the Mouse2.ico file Image needed to accompany the MousePrecise.ahk script for either running or compiling.
Thanks to the suggestion made by @guest3456, the script no longer depends on the availability of the external file. Using
the Image2Include.ahk script, the image is now embedded in the function Create_Mouse2_ico().
User avatar
jackdunning
Posts: 126
Joined: 01 Aug 2016, 18:17
Contact:

Use Center Keypad Key for Cropping Icons

01 Mar 2020, 09:01

I decided to do something with the keypad center button. Why waste it?

I added a 16-pixel jump from top-left to bottom-right to the center keypad button (5) for cropping square images in the same increments as icons (16x16, 32x32, 48x48, etc). Use Shift+NumPad5 to reverse direction.

Image

While this works for me, others may find a better use for the key.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 145 guests