v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Editing v0.34:Macros and keymaps

Jump to navigation Jump to search

Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.

You are editing a page for an older version of Dwarf Fortress ("Main" is the current version, not "v0.34"). Please make sure you intend to do this. If you are here by mistake, see the current page instead.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
 +
{{av}}
 
{{Quality|Exceptional|14:18, 4 April 2011 (UTC)}}
 
{{Quality|Exceptional|14:18, 4 April 2011 (UTC)}}
{{av}}
 
 
Playing Dwarf Fortress means lots of typing. The game has an internal macro/keymap system. Using it or any external program can save you a great deal of time when dumping, rewalling, designating, and so forth.
 
Playing Dwarf Fortress means lots of typing. The game has an internal macro/keymap system. Using it or any external program can save you a great deal of time when dumping, rewalling, designating, and so forth.
  
Line 7: Line 7:
 
The controls for creating macros within DF are as follows:
 
The controls for creating macros within DF are as follows:
  
*{{k|Ctrl}}+{{k|r}} = record (and finish recording)
+
*{{k|Ctrl}}+{{k|r}} = record
 +
*{{k|Ctrl}}+{{k|p}} = play
 
*{{k|Ctrl}}+{{k|s}} = save
 
*{{k|Ctrl}}+{{k|s}} = save
 
*{{k|Ctrl}}+{{k|l}} = load
 
*{{k|Ctrl}}+{{k|l}} = load
*{{k|Ctrl}}+{{k|u}}+number = set to repeat [number] of times
 
*{{k|Ctrl}}+{{k|p}} = play
 
  
To create a macro, press {{k|Ctrl}}+{{k|r}} to begin recording your actions. When you have recorded all the actions that you want, stop recording by hitting {{k|Ctrl}}+{{k|r}} again and save ({{k|Ctrl}}+{{k|s}}) the macro. The macro is then added to your macro list. To load a macro from the list just press {{k|Ctrl}}+{{k|l}}. You can then play the macro by pressing {{k|Ctrl}}+{{k|p}} whenever you want.  You can also set a macro to repeat by pressing {{k|Ctrl}}+{{k|u}}, typing a two digit number, and then pressing {{k|Ctrl}}+{{k|p}} to begin the playback session.  Moving your mouse from the playing window, or otherwise losing focus on Dwarf Fortress, is <s>an annoying way</s> a good way to interrupt a macro session from continuing (also the only known method anyway).
+
To create a macro press {{k|Ctrl}}+{{k|r}} to begin recording your actions. When you have recorded all the action you want stop recording by hitting {{k|Ctrl}}+{{k|r}} again and save ({{k|Ctrl}}+{{k|s}}) the macro. The macro is then added to your macro list. To load a macro from the list just press {{k|Ctrl}}+{{k|l}}. You can then play the macro using {{k|Ctrl}}+{{k|p}}.
  
There is a directory data/init/macros for them. The macros are saved in .mak format. The first line of the macro file must match the filename, or the file will not be recognized as a valid macro.  Even a recorded file for a simple macro - for example to create a 3 tiles wide ramp - may already consist of up to 50 commands listed. This is because every possible [[Key_bindings|binding of the key pressed]] is included in the macro and put in a block (and {{k|r}} for ramp has many by default).
+
There is a directory data/init/macros for them. The macros are saved in .mak format. Even a recorded file for a simple macro - for example to create a 3 tiles wide ramp - may already consist of up to 50 commands listed. This is because every possible [[Key_bindings|binding of the key pressed]] is included in the macro and put in a block (and {{k|r}} for ramp has many by default).
 
<pre>
 
<pre>
 
pressing_enter_recorded
 
pressing_enter_recorded
Line 56: Line 55:
 
It is unknown if there is the possibility of creationg loops/iterations, other programming features or comments.<br />
 
It is unknown if there is the possibility of creationg loops/iterations, other programming features or comments.<br />
  
Removing macros in-game can be done by pressing {{k|Esc}} and then selecting Keybindings > Macros. Press {{k|Backspace}} on the macros you want to delete, then press {{k|Esc}} and select "Save and Exit". This will also delete the corresponding macro file permanently. Otherwise, you can delete the corresponding .mak file from the init/macros/ folder, although that will only take effect the next time DF is run.
+
Changing, removing and adding macros while the game is running is counter-intuitive. After editing the file delete and reload the macro. Select Options->Key Bindings->Macros. Delete the macro and reload with Ctrl-l.
 
 
Changing macros while the game is running uses a counter-intuitive process. After editing the macro file, create a backup of it and remove the macro as described earlier. However, before saving the changes, place the backup file on the init/macros/ folder. Then save the changes and reload the macro with {{k|Ctrl}}+{{k|l}}.
 
 
 
Adding macros is also possible, resorting to the macro changing process. A "dummy" macro would be recorded and saved, then deleted. The macro that would be added would replace the dummy file.
 
<pre>
 
macroscreen
 
OPTIONS
 
End of group
 
STANDARDSCROLL_DOWN
 
CURSOR_DOWN
 
End of group
 
STANDARDSCROLL_DOWN
 
CURSOR_DOWN
 
End of group
 
SELECT
 
End of group
 
SELECT
 
End of group
 
End of macro
 
</pre>
 
  
 
=== Tuning macros ===
 
=== Tuning macros ===
 
The fewer commands a macro consists of, the faster it runs. This means you should avoid unnecessary steps by optimizing the "path" of your designations.
 
The fewer commands a macro consists of, the faster it runs. This means you should avoid unnecessary steps by optimizing the "path" of your designations.
  
The second and most effective way to increase speed is to remove all unnecessary commands DF recorded. These may be found in the init/macros folder and edited with any basic text editing program. The extra commands are ignored by the game but they still take time to be processed. To move a cursor 3 (up/down) or 4 (right/left) commands are recorded, most other keys are bound to more commands. Pressing {{k|d}} for example records more than 30 commands.
+
The second and most effective way to increase speed is to remove all unnecessary commands DF recorded with an external texteditor. The extra commands are ignored by the game but they still take time to be processed. To move a cursor 3 (up/down) or 4 (right/left) commands are recorded, most other keys are bound to more commands. Pressing {{k|d}} for example records more than 30 commands. Depending on what you do, you can increase the speed by 4 or more by reducing the number of commands in every group to the one you need.  
 
 
For example the code below is a simple macro that selects the digging designation, moves one square to the right, and then designates that tile to be dug.
 
<pre>
 
example
 
OPTION4
 
CUSTOM_D
 
WORLD_PARAM_DELETE
 
LEGENDS_EXPORT_DETAILED_MAP
 
A_COMBAT_DODGE
 
A_STATUS_DESC
 
A_SLEEP_DAWN
 
A_INV_DROP
 
SETUP_NOTES_DELETE_NOTE
 
BUILDJOB_TARGET_RIGHT
 
BUILDJOB_BED_DORMITORY
 
BUILDJOB_FARM_WINTER
 
BUILDJOB_RACKSTAND_KILL2
 
HOTKEY_BUILDING_DOOR
 
HOTKEY_BUILDING_CONSTRUCTION_STAIR_DOWN
 
HOTKEY_BUILDING_WORKSHOP_DYER
 
BUILDING_ORIENT_RIGHT
 
BUILDING_ADVANCE_STAGE
 
BUILDING_TRIGGER_MAX_SIZE_DOWN
 
BUILDING_TRACK_STOP_DUMP
 
HOTKEY_GLASS_DOOR
 
HOTKEY_CARPENTER_DOOR
 
HOTKEY_MASON_DOOR
 
HOTKEY_TRAP_DOOR
 
BUILDJOB_STOCKPILE_DELETE_CHILD
 
STOCKPILE_ARMOR
 
STOCKPILE_SETTINGS_DISABLE
 
STORES_DUMP
 
ORDERS_DYED_CLOTH
 
ORDERS_ZONE_DRINKING
 
D_DESIGNATE
 
D_HAULING_STOP_LC_DIR
 
D_BURROWS_DELETE
 
D_NOTE_DELETE
 
D_NOTE_ROUTE_DELETE
 
D_BITEM_DUMP
 
D_LOOK_DUMP
 
ARENA_CREATURE_SIDE_UP
 
ASSIGNTRADE_SORT
 
DESIGNATE_DUMP
 
DESIGNATE_DIG
 
ITEM_DUMP
 
D_MILITARY_DISBAND_SQUAD
 
D_MILITARY_ALERTS_DELETE
 
D_MILITARY_AMMUNITION_REMOVE_ITEM
 
D_MILITARY_DELETE_UNIFORM
 
STRING_A100
 
End of group
 
STANDARDSCROLL_RIGHT
 
CURSOR_RIGHT
 
WORLD_PARAM_INCREASE
 
A_MOVE_E
 
End of group
 
SELECT
 
CLOSE_MEGA_ANNOUNCEMENT
 
WORLD_PARAM_ENTER_VALUE
 
SETUPGAME_SAVE_PROFILE_GO
 
D_BURROWS_DEFINE
 
D_MILITARY_ALERTS_SET
 
End of group
 
SELECT
 
CLOSE_MEGA_ANNOUNCEMENT
 
WORLD_PARAM_ENTER_VALUE
 
SETUPGAME_SAVE_PROFILE_GO
 
D_BURROWS_DEFINE
 
D_MILITARY_ALERTS_SET
 
End of group
 
CUSTOM_CTRL_R
 
End of group
 
End of macro
 
</pre>
 
Here is the same code but optimized through removal of all the excess commands. Each macro also contains an addition CUSTOM_CTRL_R command at the end that may be removed as well.
 
<pre>
 
example
 
DESIGNATE_DIG
 
End of group
 
CURSOR_RIGHT
 
End of group
 
SELECT
 
End of group
 
SELECT
 
End of group
 
End of macro
 
</pre>
 
 
 
  
The third way to increase the speed of macros is to change settings in the init-files. In the [[init.txt|base init file (data/init/init.txt)]] you will find the follow lines:  
+
The third way is to change settings in the init-files. In the base init file (data/init/init.txt) you will find the follow lines:  
 
<pre>
 
<pre>
 
If you set KEY_REPEAT_ACCEL_LIMIT above one, then after KEY_REPEAT_ACCEL_START repetitions  
 
If you set KEY_REPEAT_ACCEL_LIMIT above one, then after KEY_REPEAT_ACCEL_START repetitions  
Line 186: Line 76:
  
 
</pre>
 
</pre>
 
+
This means that the speed between macro commands will gradually increase until it hits the limit. The secondary command is when the gradual increase in speed increases.
* The <code>MACRO_MS</code> setting is the number of milliseconds between macro instructions (the default, 15, allows 1000/15 instructions per second, or about 66). Decreasing this makes macros run '''faster''', although decreasing it too far can make the game unresponsive while the macro is running.
 
* The <code>KEY_REPEAT_ACCEL_START</code> and <code>KEY_REPEAT_ACCEL_LIMIT</code> settings are unrelated to macros (except while recording). See [[Technical tricks#Keyboard|Technical tricks]] for more information.
 
  
 
== External utilities ==
 
== External utilities ==
Line 196: Line 84:
  
 
=== AutoHotKey ===
 
=== AutoHotKey ===
AutoHotKey is a powerful easy-to-use scripting language that can simulate keystrokes. (among other functions)
+
#  Go to [[Utilities#AutoHotKey]] and download AutoHotKey.  Installation is simple and the program uses few system resources.
 
+
Write macro scripts (file type .ahk), which may contain any number of commands.  You activate scripts by double-clicking .ahk files and deactivate them by right-clicking the AutoHotKey icon on the task bar.  Both of these can be done at any time - even right in the middle of a game.  AutoHotKey also allows for automated activation of scripts.
To started:
 
#  Go to the [http://www.autohotkey.com/ AutoHotKey website] and download AutoHotKey.  Installation is simple and the program uses very little system resources.
 
Read through their [http://www.autohotkey.com/docs/Tutorial.htm quick-start guide] and start write your macro scripts (file type .ahk), which may contain any number of commands.  You activate scripts by double-clicking .ahk files or by assigning hotkeys to your macros.  Both of these can be done at any time - even right in the middle of a game.  AutoHotKey also allows for automated activation of scripts.
 
  
 
=== Fluxbox + xvkbd ===
 
=== Fluxbox + xvkbd ===
 
For linux, it's a quite cool solution. It's possible to create macros with outside tools, like fluxbox (linux window manager) + xvkbd (linux virtual keyboard for kiosks, with some macro capabilities). See the documentation [[Fluxbox_macros|here]].  
 
For linux, it's a quite cool solution. It's possible to create macros with outside tools, like fluxbox (linux window manager) + xvkbd (linux virtual keyboard for kiosks, with some macro capabilities). See the documentation [[Fluxbox_macros|here]].  
  
Pros:
+
*Pros
*Faster execution
+
**Faster executations
*Easier script writing
+
**Easier script writing
*Portable code
+
**Portable code
Cons:
+
*Cons
*Sometime needs timing
+
**Sometime needs timing
*Need xvkbd (Linux at least)
+
**Need xvkbd (Linux at least)
*Need some special key reservation
+
**Need some special key reservation
  
'''Please see also the [[40d:Macros and Keymaps|40d macros page]], as much of what is there works perfectly fine. If you can verify it works, please move it to this page.'''
+
:'''Please see also the [[40d:Macros and Keymaps|40d macros page]], as much of what is there works perfectly fine. If you can verify it works, please move it to this page.'''
  
 
== Useful Macro Ideas ==
 
== Useful Macro Ideas ==
Line 229: Line 114:
  
 
Start a new macro ({{k|Ctrl}}+{{k|r}}) and place the bed (selecting the first bed from the list), then move to the next bedroom in sequence. Repeat this until you reach the end of the row. If you are placing beds into multiple long rows of bedrooms, move the cursor to the first bed in the next row to make things faster. Turn off macro recording ({{k|Ctrl}}+{{k|r}}), but don't exit the build menu. You can then save your macro if you wish, though it's not necessary. Play the macro ({{k|Ctrl}}+{{k|p}}), and you have just laid out another row. Repeat until you have enough bedrooms or you run out of beds.
 
Start a new macro ({{k|Ctrl}}+{{k|r}}) and place the bed (selecting the first bed from the list), then move to the next bedroom in sequence. Repeat this until you reach the end of the row. If you are placing beds into multiple long rows of bedrooms, move the cursor to the first bed in the next row to make things faster. Turn off macro recording ({{k|Ctrl}}+{{k|r}}), but don't exit the build menu. You can then save your macro if you wish, though it's not necessary. Play the macro ({{k|Ctrl}}+{{k|p}}), and you have just laid out another row. Repeat until you have enough bedrooms or you run out of beds.
 +
 +
==== Placing Other Furniture ====
 +
 +
You can make another macro similar to the above for placing cabinets / tables / chairs / doors. Select the proper item from build menu, go to the first bedroom position wherever you want it, and repeat the record/play process above.
  
 
==== Placing Coffers ====
 
==== Placing Coffers ====
Line 240: Line 129:
 
=== Mass Selector ===
 
=== Mass Selector ===
  
With this macro you can select a lot of things at once. Extremely helpful if you want to sell a lot of junk to the caravans. Record {{k|enter}}, then {{k|down}} about 10-25 times in a row. (For some menus you may wish to use {{k|enter}}, then {{k|+}}) When the caravan arrives, your dwarves haul all the bins to your Trade Depot for sale as normal. At the trade menu, load the macro and play it as many times as you like. The macro will select all the items in your "for sale" list, saving the bins you carried them in for later use. Be sure to at least browse through the final list once you're done to avoid selling items you didn't wish to sell, i.e. items that were in the same bin as your trade goods that you wish to keep, or wood items if you're trading with the Elves.
+
With this macro you can select a lot of things at once. Extremely helpful if you want to sell a lot of junk to the caravans. Record {{k|enter}}, then {{k|down}} about 10-25 times in a row. (For some menus you may wish to use {{k|enter}}, then {{k|down}}) When the caravan arrives, your dwarves haul all the bins to your Trade Depot for sale as normal. At the trade menu, load the macro and play it as many times as you like. The macro will select all the items in your "for sale" list, saving the bins you carried them in for later use. Be sure to at least browse through the final list once you're done to avoid selling items you didn't wish to sell, i.e. items that were in the same bin as your trade goods that you wish to keep, or wood items if you're trading with the Elves.
  
 
=== Mass Trap Builder ===
 
=== Mass Trap Builder ===
Line 284: Line 173:
 
=== General Fortress Mode Hotkeys Script ===
 
=== General Fortress Mode Hotkeys Script ===
 
An attempt at speeding up various designations. Includes an up/down stair builder, a fast move up/down, and some select-and-advance keys. Please see [[user:DDR#Dwarf_Fortress_General_AHK_Script]].
 
An attempt at speeding up various designations. Includes an up/down stair builder, a fast move up/down, and some select-and-advance keys. Please see [[user:DDR#Dwarf_Fortress_General_AHK_Script]].
 +
 +
 +
 +
{{av}}

Please note that all contributions to Dwarf Fortress Wiki are considered to be released under the GFDL & MIT (see Dwarf Fortress Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)