Hotkey mods for Hammer using AutoHotkey

Discussion in 'Tutorials & Resources' started by duppy, Aug 17, 2014.

  1. duppy

    duppy L1: Registered

    Positive Ratings:
    Hey guys, just wanted to share this AutoHotkey script I've been using for a while now....maybe someone will find it useful:

    See spoiler for actual code.

    ; Hotkey mods for Valve's Hammer editor
    ; Created by Duppy (aka Valacar)
    ; Made with AutoHotkey version v1.1.10.01 (aka AutoHotkey_L)
    ; Last updated: August 16th, 2014
    #SingleInstance force
    SendMode Input
    SetWorkingDir %A_ScriptDir%
    SetTitleMatchMode 1  ; "starts with" title matching mode
    	Menu, Tray, Icon, D:\Games\Team Fortress 2\bin\hammer.exe  ; system tray icon for this AHK script
    isolateToggle := false  ; global var to track isolating objects (quickhide toggle)
    ; close this script if Hammer window no longer exists; checked every 10 seconds
    SetTimer, check_window_exists, % 10 * 1000
    #IfWinActive Hammer ahk_class VALVEWORLDCRAFT   ; all mouse/keyboard shortcuts only apply to Hammer
    ; 'I' key isolate selected object(s) by toggling QuickHide
    	global isolateToggle := ! isolateToggle
    	if (isolateToggle)
    		Send ^h   ; ctrl-h = QuickHide unselected objects
    		Send u    ; u = unhide QuickHide objects
    ; ALT+I toggles object bounding boxes, since 'I' without ALT key isolates objects
    	Send i
    ; CTRL+SHIFT+V = Edit>Paste Special (normally has no hotkey)
    	WinMenuSelectItem, A, , Edit, Paste Special...
    ; Use middle mouse buttons to pan/move around in 2D and 3D views
    	Send {Space down}{LButton down}
    	KeyWait MButton
    	Send {Space up}{LButton up}
    ; ALT+MouseWheelUp presses ']' (increase grid size)
    	Send ]
    	Sleep 10                       ; wait 10ms so we don't get old snap size
    	StatusBarGetText, GridText, 6  ; get grid snap size from statusbar (in 6th position)
    	Tooltip, %GridText%            ; show tooltip
    	SetTimer, RemoveToolTip, -750  ; disable tooltip.  note: time must be negative to do it once
    ; ALT+MouseWheelDown presses '[' (decrease grid size)
    	Send [
    	Sleep 10                       ; wait 10ms so we don't get old snap size
    	StatusBarGetText, GridText, 6  ; get grid snap size from statusbar (in 6th position)
    	Tooltip, %GridText%            ; show tooltip
    	SetTimer, RemoveToolTip, -750  ; disable tooltip.  note: time must be negative to do it once
    ; Mouse4 side button presses ALT+Enter (properties window)
    	Send {Alt down}{Enter}{Alt up}
    ; ALT+Mouse4 side button presses SHIFT+a (face edit sheet)
    	Send +a
    ; Mouse5 side button presses CTRL+e (center 2D view on selection)
    	Send ^e
    ; SHIFT+Mouse5 button presses CTRL+SHIFT+e (center 3D view on selection)
    	Send ^+e
    ; Double tap SPACEBAR to toggle maximizing of the 2d and 3d viewports (similar to Maya)
    	if (A_PriorHotkey <> "~Space" or A_TimeSincePriorHotkey > 400)
    		; Too much time between presses, so this isn't a double-press.
    		KeyWait, Space
    	Send +z  ; maximize active viewport (shift+Z)
    ; ALT+B Opens/Closes (i.e. toggle) texture browser windows
    	IfWinExist, Texture ahk_class #32770
    		WinClose Texture ahk_class #32770
    		SetControlDelay -1
    		ControlClick, Button4,,&Browse...,,, NA
    ; ALT+A Applies Current Texture
    	PostMessage, 0x111, 32867  ; WM_COMMAND, 32867 = Apply Current Texture
    ; ALT+S snaps object to grid (Same as ctrl+b. Previously increased grid size)
    	Send ^{b}
    	ToolTip   ; remove tooltip
    	; if Hammer is closed, kill this script
    	IfWinNotExist, ahk_class VALVEWORLDCRAFT
    ; Textures browser window specific stuff
    #IfWinActive Textures ahk_class #32770
    	; ALT+B close browser if already open (i.e. toggle).
    	; Note: ALT+B is also defined in Hammer section above; this part only closes the window
    		IfWinExist Texture ahk_class #32770
    			Send {Esc}
    WriteLn(str) ; output line to STDOUT for debugging in my text editor (sublime)
    	FileAppend, %str%`n, *
    ;   ID: 32999 = Toggle Selection by Handle
    ;   ID: 33226 = Toggle NODRAW textures
    ;   ID: 32965 = Toggle Group Ignore
    ;   ID: 32925 = Create New Vis Group (from selection)
    ;   ID: 32962 = Edit Cordon Bounds
    ;   ID: 32960 = Toggle Cordon State
    ;   ID: 33114 = Toggle Helpers
    ;   ID: 32867 = Apply Current Texture
    ;   ID: 32913 = Toggle Texture Application (Face Edit Sheet)
    ;Texture Browser Window = ahk_class #32770
    ; spin control = msctls_updown32

    It basically just modifies and adds some hotkeys to Hammer. I made it because I wanted to be able to use more of my mouse buttons for often used shortcuts...and I wanted to add things like toggles, or hotkeys for tools that are only accessed from the menu or toolbar buttons. Anyway, here's what it does:

    • 'i' key will toggle QuickHide for current selection (I call it 'isolate'). In other words it hides everything except your selection and then pressing it again will un-hide everything. Essentially combines Ctrl-H and 'U' into one key.
    • ALT+i - toggle bounding boxes. It's what the 'i' key did previously.
    • Middle Mouse Button - Press and hold to pan/move the 2d and 3d window
    • ALT+MouseWheelUp - increases grid size and shows current size as a tooltip
    • ALT+MouseWheelDown - decreases grid size and shows current size as a tooltip
    • Double tap SPACEBAR - toggle maximizing of the 2d and 3d viewports (similar to Maya)
    • ALT+B - toggles Texture browser window open
    • ALT+A - Apply current texture
    • ALT+S - Snap to grid
    • CTRL+SHIFT+V - Paste Special (normally has no hotkey)
    • Mouse4 (side button) -brings up the Properties window
    • Mouse5 (side button) - center 2D view on selection
    • SHIFT+Mouse5 - center 3D view on selection
    • ALT+Mouse4 - bring up Face Edit Sheet window

    To install it, you'll need AutoHotkey_L. Currently I'm using v1.1.10.01, and I haven't tested it on anything else, so make sure to get the 1.1.x.x version. You can find it here:

    I personally keep my AutoHotkey scripts in "Documents\AHK Scripts\" but you should be able to put the script anywhere. Just double click it to run it, and then start up Hammer. You may want to add it to your Hammer.bat file to make that easier...mine looks like this:

    @echo off
    :: Batch file to launch Hammer editor with proper environment
    :: Confirm VPROJECT variable is set
    call "%~d0%~p0check_sdk_env.bat"
    :: Launch Hammer
    echo Starting hammer...
    echo Executing "%~d0%~p0hammer.exe" %*
    start "" "D:\Documents\Mark\AutoHotkey Scripts\Hammer.ahk"
    start "" "%~d0%~p0hammer.exe" %*

    Also, here's a few links that might be useful:

    If you have trouble getting it to work, or if you need help customizing it, let me know.

    BTW, I have another script that lets me press ALT + an arrow key to rotate and mirror textures, but it's a bit buggy. I vaguely remember doing this is QERadiant back in the Quake days. Maybe I'll post it in the future if there's any interest ;)
    • Thanks Thanks x 2
  2. YM

    aa YM LVL100 YM

    Positive Ratings:
    You have some that are already on existing hotkeys:
    shift+t - applies current texture
    shift+z (haven't used it in 5 years since getting 2 monitors) - toggles fullscreen for a 2d/3d view
    shift+w - toggle grid snapping
    alt+enter - open properties
    ctrl+e - centres 2d views on selection
    ctrl+shift+e - centres 3d views on selection
    shift+a - opens face edit sheet
    h - hide selected
    ctrl+h - hide unselected
    u - unhide all

    Admittedly some of the ones you've got for mouse buttons may be a little more convenient, but many of us don't have those buttons available to us, and they already have hotkeys! (Your toggle for hide/unhide is nice though)

    Ones I thought people knew but didn't:
    ctrl+b - snaps a selection to the grid
    crtl+shift+b - snaps every object within a selection to the grid individually
    alt+RMB - on any face while in displacement geo editing 'steals' that face's normal to use as the current axis
    c - toggles radial culling. If you suddenly find hammer drops to 10% of its usual framerate, you may have hit it by accident.
    Last edited: Aug 18, 2014
  3. A Boojum Snark

    aa A Boojum Snark Toraipoddodezain Mazahabado

    Positive Ratings:
    That's ignore groups, grid snap is shift+w.

    and in addition to YM's list, holding spacebar lets you move the viewports around (like with photoshop and a lot of other programs).

    I have a question though, can a toggle hotkey "break" and become reversed if you use it while it is invalid to do so? (e.g. trying to hide when you have no selection)
  4. duppy

    duppy L1: Registered

    Positive Ratings:
    Yeah, in hindsight I probably shouldn't have shown my own remapping of keys to already existing hotkeys. I guess, more or less, I'm showing that you can remap your keys to something you find more comfortable....with my own setup as an example. For me, I prefer taking advantage of my extra mouse buttons, as well as allowing my left hand to do most of the work.

    Thanks for pointing out Shift+T, btw....not sure how I missed that :blushing: I used a more technical way of getting that working when I didn't have to. Must've missed it because the "Apply current texture" button on the toolbar doesn't mention the hotkey like it does for all the other buttons.