Jump to content

AutoHotkey script: Hotkeys to change Font size or Brush size on the fly


Recommended Posts

I have to annotate screenshots a lot and when typing using the Text tool, I have often wished for the ability to adjust Font size on the fly using shortcut keys.

 

Being able to use keys means that it would no be longer necessary to stop typing, move the mouse to the Font size control in the toolbar and adjust the size by:

  • picking from the dropdown list
  • or typing in the size box
  • or rolling the mouse wheel while the pointer is over the control.

 

Searching the forum reveals that shortcut keys for Font size have been requested multiple times in the past.

 

So it's about time we had a solution.

 

The AutoHotkey script 'PDN Adjust Font and Brush Size.ahk'  provides the capability to adjust Font size using the hotkeys:

Ctrl+[              Decrease by 1
Ctrl+]              Increase by 1
Ctrl+Shift+[   Decrease by 5
Ctrl+Shift+]   Increase by 5

 

The keys can be held down for continuous adjustment.
 

In addition, the script harmonizes the keys for adjusting Brush size, available when the Paintbrush, Eraser, Clone Stamp, Recolor, Line/Curve or Shapes tools are selected, to be the same as the keys listed above.

 

Note that paint.net's native use of [ and ] for decreasing/increasing the Brush size by 1 pixel still works but it's easier (IMO) to use the above Ctrl keys for Font size (and Brush size) in a consistent manner, especially as Microsoft Word also uses Ctrl+[ and Ctrl+] to adjust Font size by 1 point.

Here's the script. It looks quite long but that's simply because it is heavily annotated with comments.

 

Spoiler
; AutoHotKey script: 'PDN Adjust Font and Brush Size.ahk'
;
; Currently (as at paint.net 5.0.8), when typing using the Text tool it is not possible
; to adjust Font size on the fly using a keypress. This script provides that
; capability using the hotkeys:
;   Ctrl+[        Decrease by 1
;   Ctrl+]        Increase by 1
;   Ctrl+Shift+[  Decrease by 5
;   Ctrl+Shift+]  Increase by 5
;
; The keys can be held down for continuous adjustment.
;
; Using these keys means that it is no longer necessary to stop typing, move the
; mouse to the Font size control and adjust the size by:
; - picking from the dropdown list
; - typing in the size box
; - rolling the mouse wheel while the pointer is over the control.
;
; In addition, the script harmonizes the keys for adjusting Brush size, available
; when the Paintbrush, Eraser, Clone Stamp, Recolor, Line/Curve or Shapes tools
; are selected, to be the same as the keys listed above.
;
; Note that paint.net's native use of [ and ] for decreasing/increasing the Brush
; size by 1 pixel still works but it's easier (IMO) to to use the above Ctrl keys
; for Font size (and Brush size) in a consistent manner, especially as Microsoft
; Word also uses Ctrl+[ and Ctrl+] to adjust Font size by 1 point.
;
;
; Usage: Run this script manually or create a shortcut to the .ahk file in the
; Windows Startup folder, which can be found by entering shell:startup in Windows
; File Explorer's address bar.
; The usual location is:
; C:\Users\<users_folder>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

; Require the use of AHK v2.0 or later
#Requires AutoHotkey v2

; Allow only one instance of the script to be active.
; If the script is re-run (e.g. after editing the .ahk), the currently running
; instance will be replaced with the new version
#SingleInstance Force


; -----------------------------------------------------------------------------
; The hotkeys have effect only if paint.net is the active window
;
#HotIf WinActive("ahk_exe paintdotnet.exe")

; Hotkey Ctrl+[  Decrease the Font size or Brush size by 1
^[:: AdjustSize(-1)

; Hotkey Ctrl+]  Increase the Font size or Brush size by 1
^]:: AdjustSize(1)

; Hotkey Ctrl+Shift+[  Decrease the Font size or Brush size by 5
^+[:: AdjustSize(-5)

; Hotkey Ctrl+Shift+]  Increase the Font size or Brush size by 5
^+]:: AdjustSize(5)


;-------------------------------------------------------------------------------
; AdjustSize() decreases/increases the Font or Brush size by delta points (or pixels)
; depending on which control is displayed in the toolbar.
; Has no effect if neither control is displayed
;
AdjustSize(delta)
{
    ; Get the ClassNN of the size control that is currently displayed
    SizeCtrl := GetToolbarSizeControl()
    
    if !SizeCtrl
        ; Nothing to do as neither the Font size nor Brush size control is displayed
        return

    ; Read the current size from the control
    CurrentSize := ControlGetText(SizeCtrl)

    ; Proceed only if the current size is a number. This guards against the user
    ; having mistakenly typed non-numeric characters in the control
    if !IsNumber(CurrentSize)
        return

    ; Calculate the new size but don't allow it to become less than 1
    NewSize := CurrentSize + delta
    if NewSize < 1
        NewSize := 1

    ; Clear the current size in the control and enter the new size.
    ; NB. Don't try to use ControlSetText() to set the new size because paint.net
    ; won't be notified of the change of value 
    ControlSetText("", SizeCtrl)
    EditPaste(NewSize, SizeCtrl)
}


;-------------------------------------------------------------------------------
; GetToolbarSizeControl returns the ClassNN of the currently displayed 'Font size'
; or 'Brush size' Edit control.
; Returns an empty string if neither size control is currently displayed.
;
; The ClassNN of the Font and Brush size Edit controls is respectively "Edit1" and
; "Edit2" (or vice-versa) depending on the order in which the user activates the Tools.
; This is because paint.net does lazy creation of the necessary toolbar controls only
; when they are needed.
;
GetToolbarSizeControl()
{
    ; Determine whether the control having a ClassNN of "Edit1" has been created
    ; and is currently displayed.
    ; TargetError will be thrown if "Edit1" does not exist yet.
    try
    {
        if ControlGetVisible("Edit1")
            ; Return the control's ClassNN
            return "Edit1"
    }
    catch TargetError
        return

    ; We've reached here because "Edit1" exists but is not currently displayed, so
    ; now determine whether the control having a ClassNN of "Edit2" has been created
    ; and is displayed.
    ; TargetError will be thrown if "Edit2" does not exist yet.
    try
    {
        if ControlGetVisible("Edit2")
            ; Return the control's ClassNN
            return "Edit2"
    }
    catch TargetError
        return

    ; We've reached here because "Edit1" and "Edit2" exist but currently neither
    ; is displayed
    return
}

 



Do give this script a go. It works well and it's great to easily adjust text size.

If you encounter any problems, please let me know.

 

 

 

 

  • Upvote 1
Link to comment
Share on other sites

  • Tactilis changed the title to AutoHotkey script: Hotkeys to change Font size or Brush size on the fly

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...