Skip to content

Methods and Properties

Edison Hua edited this page Apr 18, 2026 · 145 revisions
See: Extended Methods and Properties for a complete list of methods and properties.

All methods return this to allow infinite chaining.

#include TextRender.ahk
tr := TextRender().Draw("hello").OnEvent("LeftMouseDown", tr.EventCopyData).Render("world!", "y:66% c:random")

Settings and Options

Debug Events

  • Left Click - Hold to drag.
  • Middle Click - Display current window coordinates.
  • Right Click - Copy data to clipboard.

Change Events and Callbacks

  • DefaultEvent() / DefaultEvents() - Left Click to drag. Right Click to close. Middle Click is disabled.
  • NoEvent() / NoEvents() - Removes all mouse events.

Window Styles

  • AlwaysOnTop() - Toggle. Keeps the window above other windows.
  • ClickThrough() - Toggle. Makes the window click through when set, so the underlying window receives mouse events.
  • NoActivate() - Toggle. Prevents the window from becoming the foreground window. Stops the Windows Taskbar from overlaying a fullscreen application.
  • TopMost() - Brings to the top of the z-order, above other AlwaysOnTop windows. Sets AlwaysOnTop to true.
  • ToggleStyle(long) and ToggleExStyle(long) are used to toggle window styles and extended window styles.

Show / Hide

  • Show() - Shows the window by rendering it with an opacity of 255.
  • Hide() - Hides the window by rendering it with an opacity of 0.
  • ShowHide() - Toggles between Show() and Hide().

Note 1: WinExist(tr) will always return true (hwnd) even when the window is hidden.

Note 2: WinGetTransparent(tr) will always return "" (Off) because it is fully visible. It has been rendered with an opacity of 0, which is different from setting the window transparency.

Note 3: To check whether a TextRender instance is hidden use tr.windowstate <= 1. A windowstate of 🪟0 and 🪟1 mean the window is hidden. Windowstates 🪟2 and 🪟3 mean the window is visible. See Extended Methods and Properties for more information, but to keep it short, the difference between 🪟0 and 🪟1 is that 🪟0 is a destroyed window and the difference between 🪟 2 and 🪟 3 is that 🪟3 is an animated window.

Drawing and Graphics

Render(Text, BackgroundStyle, TextStyle) - Shows the completed render on screen. Calls Draw() when parameters are passed.

; Create a TextRender instance and shows text on the screen.
tr := TextRender()
tr.Render("oof")

Draw(Text, BackgroundStyle, TextStyle) - Draws a separate layer in the bitmap. Call Render() to display everything on screen.

; Draw is useful for combining multiple layers of text.
tr := TextRender()
tr.Draw("happy birthday!", "x:400px w:1000 c:Skyblue m:0", "s:72pt j:3")
tr.Draw("cute!", "x:400 y:400 c:Gold m:0", "x:552 s:72pt q:4")
tr.Render() ; Updates the screen with the contents of the bitmap.

Clear() - Destroys the window, erases the bitmap, and forgets all saved recipes.

; Clears the text from screen.
tr := TextRender("hi!","m:0 c:Random", "s:15%")
tr.Wait(2000)
tr.Clear()

Resolve() - Marks the bitmap for overwriting with the next call to Draw().

; If the bitmap is not marked for deletion, any changes to the bitmap will carry over.
tr := TextRender()
tr.Draw("Prepare for trouble!", "c:Random", "s:20%")
tr.Save("1.png")

; The bitmap is not cleared, so the previous image is drawn over...
tr.Draw("And make it double!")
tr.Save("2.png")

; Calling Resolve() will allow Draw() to Erase() the bitmap when needed.
tr.Resolve()
tr.Draw("And make it double!")
tr.Save("3.png")

Wait(t?) - Waits out any remaining cooldown and optionally suspends for an additional t milliseconds.

tr := TextRender()

    ; Waits 250 ms remaining cooldown
    .Render("Apple", "t: 250ms c: Random")
    .Wait() 
    .Render("Banana", "t: 250ms c: Random")
    .Wait()

    ; In addition to the 250 ms cooldown, wait 1 second more.
    .Render("Cherry", "t: 250ms c: Random")
    .Wait(1000)
    .Render("Dragonfruit", "t: 250ms c: Random")
    .Wait(1000)

Remember(Text, BackgroundStyles, TextStyles) - Stores recipes.

Forget(n?) - Forgets all recipes. If n is passed, the last n number of recipes is forgotten.

Paint() - Renders all saved recipes to the window and forgets them.

tr := TextRender()
tr.Remember("1", "x:left color:Random", "s:5vmin")
tr.Remember("2", "x:center color:Random", "s:5vmin")
tr.Remember("3", "x:right color:Random", "s:5vmin")
tr.Paint()

Free() - Deletes all memory allocated for the bitmap. This operation does not affect the current window on screen or any saved recipes. Reduces memory usage by ~60%. For performance reasons, this is not done at the end of every operation. This operation is completely reversible. Subsequent calls to Draw() or Render() will reallocate the bitmap and redraw from any saved recipes. Manually call Redraw() to return to the previous state before Free() was called.

; Decreases memory usage.
tr := TextRender("Pangrams have subjects like “dewy fox quiz.”")
tr.Free()

Save(filepath?, quality?) - Saves bitmap to file.

tr := TextRender("colorful text", "c:Random", "s:10vmin f:(Comic Sans)").Save()

Screenshot(filepath?, quality?) - Takes a screenshot of the window. Useful when the background is transparent.

tr := TextRender("strike a pose", "c:None", "f:(Century Gothic)").Screenshot()

Animations

tr := TextRender()                 ; (Optional) Save styles here
tr.Draw("spooky", "c:random t:1s") ; Can't use Render(text, styles)
tr.FadeIn(3000)                    ; Fades in over 3 seconds
tr.Wait()                          ; Waits 1 second (see above!)
tr.FadeOut(250)                    ; Fades out in 250 milliseconds

The following functions can be used as an alternative to Render()

  • FadeIn(t)
  • FadeOut(t)

Properties

data - Gets the most recent text or image parameter.

chars, words, lines - Gets the number of characters, words, or lines displayed on screen. Supports all languages.

Events and Callbacks

Use like OnEvent("LeftMouseDown", callback) or OnLeftMouseDown(callback) Event names are inspired by Rainmeter.

  • OnLeftMouseDown
  • OnLeftMouseUp
  • OnLeftMouseDoubleClick
  • OnRightMouseDown
  • OnRightMouseUp
  • OnRightMouseDoubleClick
  • OnMiddleMouseDown
  • OnMiddleMouseUp
  • OnMiddleMouseDoubleClick
  • OnX1MouseDown
  • OnX1MouseUp
  • OnX1MouseDoubleClick
  • OnX2MouseDown
  • OnX2MouseUp
  • OnX2MouseDoubleClick
  • OnMouseScrollUp
  • OnMouseScrollDown
  • OnMouseScrollLeft
  • OnMouseScrollRight
  • OnMouseOver (not implemented)
  • OnMouseLeave (not implemented)

Built-in event hooks (yes, every method has an event hook, even the useless ones)

  • OnDelete - Called when the object is garbage collected (when __Delete is called)
  • OnRemember
  • OnForget
  • OnDestroy - Called when TimeOut() and Destroy() is called
  • OnCreate - Called when the window is created or recreated after being destroyed
  • OnInvalidate
  • OnValidate
  • OnStop
  • OnStart
  • OnResume
  • OnUpdateLayered
  • OnHide
  • OnShow
  • OnScreenshot
  • OnFree
  • OnAllocate
  • OnErase
  • OnFill
  • OnRecycle
  • OnResolve
  • OnSave
  • OnClear
  • OnTimeout - Called when time is set in the styles causing the window to expire
  • OnFlush
  • OnPaint
  • OnDraw
  • OnRender - Called whenever the .Render() method is called
  • OnReallocate
  • OnRedraw
  • OnRerender - Called when the screen size, resolution, dpi, or orientation changes
  • OnWait
  • OnCooldown
  • OnSuspend
  • OnAnimate - Called whenever an animation happens, including FadeIn and FadeOut
  • OnFadeIn
  • OnFadeOut

Default events can be retrieved via:

  • (this) => this.EventCopyData - Copies text to the clipboard.
  • (this) => this.EventDestroyWindow - Alias of Destroy().
  • (this) => this.EventMoveWindow - Hold to drag.
  • (this) => this.EventMoveWindowStorePosition - Hold to drag and the new position is remembered for next render.
  • (this) => this.EventMoveWindowStorePositionAndRender - Hold to drag and render areas that were clipped off-screen.
  • (this) => this.EventShowCoordinates - Display current window coordinates.

Set an event:

tr := TextRender("Left Click will show the window coordinates")
tr.OnLeftMouseDown((this) => this.EventShowCoordinates)        ; ✅ Recommended way to set an event
tr.OnLeftMouseDown(TextRender.prototype.EventShowCoordinates)  ; ✅ Alternative use of the class prototype
tr.OnLeftMouseDown(tr.EventShowCoordinates)                    ; ❌ Do not use. ⚠️ Contains a circular reference!

Delete an event:

tr := TextRender("This box cannot be dragged")
tr.OnLeftMouseDown() ; Leave the parameter blank.

Delete all events:

tr.NoEvent()
tr.NoEvents()

Custom event using a built-in function:

tr := TextRender("If you click me I will vanish really really slowly...")
tr.OnLeftMouseDown((this) => this.FadeOut(8000))  ; Fade out over 8 seconds

Custom event using a function:

#Requires AutoHotkey v1.1.33+
tr := TextRender("Click to change color", "w:500px h:500px m:0 c:random", "v:center")
tr.OnLeftMouseDown(Func("fn")) ; Overrides the default click to drag event.

fn(this) { ; Optional Parameter: this refers to the TextRender instance that is calling this function
    this.render("Keep clicking!", "w:500px h:500px m:0 c:random", "v:center")
}
Esc:: ExitApp
#Requires AutoHotkey v2.0-a
tr := TextRender("Click to change color", "w:500px h:500px m:0 c:random", "v:center")
tr.OnLeftMouseDown(fn) ; Overrides the default click to drag event.

fn(this) { ; Optional Parameter: this refers to the TextRender instance that is calling this function
    this.render("Keep clicking!", "w:500px h:500px m:0 c:random", "v:center")
}
Esc:: ExitApp

When creating a custom event using a method, omit "this" as the first parameter.

#Requires AutoHotkey v1.1.33+
tr := TextRender("Click me?", "x:200 y:200 w:500px h:500px m:0 c:random", "v:center")
tr.OnLeftMouseDown(some_class.fn)

class some_class {
    fn() { ; Do not include "this" as a parameter. It is implicit.
        MsgBox % "x:`t" this.x
            .  "`ny:`t" this.y
            .  "`nw:`t" this.w
            .  "`nh:`t" this.h
    }
}
Esc:: ExitApp
#Requires AutoHotkey v2.0-a
tr := TextRender("Click me?", "x:200 y:200 w:500px h:500px m:0 c:random", "v:center")
tr.OnLeftMouseDown(some_class.prototype.fn)

class some_class {
    fn() { ; Do not include "this" as a parameter. It is implicit.
        MsgBox   "x:`t" this.x
            .  "`ny:`t" this.y
            .  "`nw:`t" this.w
            .  "`nh:`t" this.h
    }
}
Esc:: ExitApp

Coordinates

Rect() - Returns canvas coordinates [x, y, w, h].

Bounds() - Returns canvas coordinates [x, y, x2, y2].

Export

CopyToHBitmap() / RenderToHBitmap() - Returns a handle to a GDI hBitmap in 32-bit pre-multiplied alpha RGB.

CopyToBitmap() / RenderToBitmap() - Returns a pointer to a GDI+ bitmap in 32-bit ARGB.

CopyToBuffer() - Returns a pointer to pixel values. You must call GlobalFree to release. Call GlobalSize to get the size.

Hash() - Returns a CRC32 hash of the bitmap. Can be used to check whether the bitmaps are identical. Use.OnErase(callback) and .OnDraw(callback) to intercept the clearing of the canvas and drawing onto the canvas for faster speed.

DrawOnGraphics(g) / DrawOnBitmap(pBitmap) / DrawOnHDC(hdc) - Can be used to draw on another graphics surface. Returns an object with the following values.

Clone this wiki locally