Hotkey mods for Hammer using AutoHotkey

duppy

L1: Registered
Feb 16, 2012
35
8
Hey guys, just wanted to share this AutoHotkey script I've been using for a while now....maybe someone will find it useful:

http://www.mediafire.com/view/j7ibir4vd6wj6li/Hammer.ahk

See spoiler for actual code.

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
#NoEnv
#Warn

SendMode Input
SetWorkingDir %A_ScriptDir%

SetTitleMatchMode 1  ; "starts with" title matching mode

try
{
	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

return


;------------------------


#IfWinActive Hammer ahk_class VALVEWORLDCRAFT   ; all mouse/keyboard shortcuts only apply to Hammer


; 'I' key isolate selected object(s) by toggling QuickHide
i::
	global isolateToggle := ! isolateToggle
	if (isolateToggle)
		Send ^h   ; ctrl-h = QuickHide unselected objects
	else
		Send u    ; u = unhide QuickHide objects

return


; ALT+I toggles object bounding boxes, since 'I' without ALT key isolates objects
!i::
	Send i
return


; CTRL+SHIFT+V = Edit>Paste Special (normally has no hotkey)
^+V::
	WinMenuSelectItem, A, , Edit, Paste Special...
return


; Use middle mouse buttons to pan/move around in 2D and 3D views
MButton::
	Send {Space down}{LButton down}
	KeyWait MButton
	Send {Space up}{LButton up}
Return


; ALT+MouseWheelUp presses ']' (increase grid size)
!WheelUp::
	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
return


; ALT+MouseWheelDown presses '[' (decrease grid size)
!WheelDown::
	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
return


; Mouse4 side button presses ALT+Enter (properties window)
XButton1::
	Send {Alt down}{Enter}{Alt up}
return


; ALT+Mouse4 side button presses SHIFT+a (face edit sheet)
!XButton1::
	Send +a
return


; Mouse5 side button presses CTRL+e (center 2D view on selection)
XButton2::
	Send ^e
return


; SHIFT+Mouse5 button presses CTRL+SHIFT+e (center 3D view on selection)
+XButton2::
	Send ^+e
return


; Double tap SPACEBAR to toggle maximizing of the 2d and 3d viewports (similar to Maya)
~Space::
	if (A_PriorHotkey <> "~Space" or A_TimeSincePriorHotkey > 400)
	{
		; Too much time between presses, so this isn't a double-press.
		KeyWait, Space
		return
	}
	Send +z  ; maximize active viewport (shift+Z)
return


; ALT+B Opens/Closes (i.e. toggle) texture browser windows
!B::
	IfWinExist, Texture ahk_class #32770
	{
		WinClose Texture ahk_class #32770
	}
	else
	{
		SetControlDelay -1
		ControlClick, Button4,,&Browse...,,, NA
	}
return


; ALT+A Applies Current Texture
!A::
	PostMessage, 0x111, 32867  ; WM_COMMAND, 32867 = Apply Current Texture
return


; ALT+S snaps object to grid (Same as ctrl+b. Previously increased grid size)
!S::
	Send ^{b}
return


;------------------------


RemoveToolTip:
	ToolTip   ; remove tooltip
return


check_window_exists:
	; if Hammer is closed, kill this script
	IfWinNotExist, ahk_class VALVEWORLDCRAFT
		ExitApp
return


;------------------------


; 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
	!B::
		IfWinExist Texture ahk_class #32770
			Send {Esc}
	return

#IfWinActive


;------------------------


WriteLn(str) ; output line to STDOUT for debugging in my text editor (sublime)
{
	FileAppend, %str%`n, *
}


;---[NOTES]-----------------------------------------------------

;WM_COMMAND(0x111)
;   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:

http://ahkscript.org

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:

Code:
@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 ;)
 

YM

LVL100 YM
aa
Dec 5, 2007
7,135
6,056
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:

A Boojum Snark

Toraipoddodezain Mazahabado
aa
Nov 2, 2007
4,775
7,670
ctrl+w - toggle grid snapping
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)
 

duppy

L1: Registered
Feb 16, 2012
35
8
You have some that are already on existing hotkeys:

...

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)

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.