The Forest

The Forest

Not enough ratings
How To Remap Locked Keys and Mouse Buttons
By fosley
A walkthrough of how to bind mouse buttons, keyboard buttons that aren't allowed by default, etc. in The Forest. Requires some technical skills but isn't super difficult.
2
   
Award
Favorite
Favorited
Unfavorite
Intro
I recently started playing The Forest, and the first thing I noticed is that I couldn't rebind mouse4 to the Run command. So I started searching around and found that it's generally impossible. Undeterred, I decided to see what I can accomplish anyways.

After a couple days of dinking around, I have successfully bound mouse4 to the Run command. Read on to find out how.
  • Obligatory warning that the registry is important, and if you screw it up you can brick your OS. Don't be dumb and you should be fine.
  • If you've made substantial changes to your keybinds already, I'd save a copy of the exported keys you can go back to instead of starting from scratch.
Process overview:
1. Extract keybind from the registry.
2. Convert to xml.
3a. Edit an existing bind you want to change. OR
3b. Add a new bind that didn't exist.
4. Convert back to hex.
5. Merge new keybinds with the registry.
6. Enjoy.
Background Information
  1. The bindings are stored in the registry at
    Computer\HKEY_CURRENT_USER\SOFTWARE\SKS\TheForest
  2. There are four keys starting with UserRemapping that seem to hold the information we want.
  3. The first two keys appear to be joystick/gamepad related:
    UserRemapping_v3&playerName=System&dataType=InputBehavior&id=0_h1699203952
    UserRemapping_v3&playerName=Player&dataType=InputBehavior&id=0_h2177795462
  4. The third contains all the keyboard mapping information:
    UserRemapping_v3&playerName=Player&dataType=ControllerMap&controllerMapType=KeyboardMap&categoryId=0&layoutId=1&hardwareIdentifier=Keyboard_h4275277544
  5. The fourth contains all the mouse mapping information:
    UserRemapping_v3&playerName=Player&dataType=ControllerMap&controllerMapType=MouseMap&categoryId=0&layoutId=0&hardwareIdentifier=Mouse_h3996039753
  6. All the bindings are stored in a binary format. We can convert to xml format pretty easily using online converters.
  7. The keybindings use the Rewired[guavaman.com] API for mapping.
  8. We can acquire keyboard and mouse maps from the Rewired website. Go here[guavaman.com], then download the CSV files for keyboard and mouse. They'll open in Excel spreadsheet or similar. You can use them to determine what element Id and KeyCode correspond to what buttons on your keyboard or mouse.
  9. The actions are defined internally to the game. Without reverse engineering the game's executable or having the source code, this will likely be trial and error. It's possible there are actions we could bind to but don't know about them yet.
  10. Rewired allows multiple commands to be bound to a single action. The game doesn't know if you pressed mouse4 or leftControl, because Rewired takes care of that. If either of those is bound to Sprint, the game simply knows Sprint was pressed and goes from there. This potentially means we can create some complex sequences if we know the action ids and so forth. It also means we can have secondary bindings if desired.
  11. Rewired allows combination keys, such as Shift+J or Ctrl+Shift+W. This seems to be supported in game, allowing binds such as 1-4 for items, then Alt+1-4 for lighter/compass/etc.
Converting from Registry to XML
  1. Open the registry (Windows+R, then run regedit), then navigate to Computer\HKEY_CURRENT_USER\SOFTWARE\SKS\TheForest.
  2. Right-click TheForest in the left pane, then click Export.
  3. Name it something, like "The Forest", then save it somewhere, like your desktop.
  4. Right click the file on your desktop and "open with" a text editor. I prefer Notepad++.
  5. Find the keys you want to look for. Search for "hardwareIdentifier=Keyboard" and/or "hardwareIdentifier=Mouse".
  6. Select everything after "=hex:" until the last of the hex characters (there will be a new line with another key right after the hex characters, or a blank line at the end of file). Ignore the "=hex:" portion and just select the hex itself.
  7. Copy the hex into a converter. I used http://www.unit-conversion.info/texttools/hexadecimal. Make sure to select hex to text (text to hex was selected by default for me).
  8. Copy the converted text into an xml formatter to make it easy to read. I used https://www.freeformatter.com/xml-formatter.html and used 4 spaces per indent, but you can use default settings.
  9. Copy that xml into Notepad++ to start digging through it.
  10. Repeat steps 6 to 9 if you want to do multiple keys (keyboard and mouse, for example).
Finding your Action Codes
Looking at my current keybinding, I can figure out what a specific action code is.
  1. I see that Run is bound to Left Shift.
  2. I can look in the Rewired spreadsheet for keyboard to find that Left Shift is KeyCode value 304, Element Identifier Id 117, Element Identifier Type 0. (Note: while all the keyboard Element Types should be 0 according to the spreadsheet, they're listed as 1 in the xml. 1 seems to work, so go with it.)
  3. Looking through the xml I converted, I can search for "<elementIdentifierId>117<" to find the corresponding key. It's assigned to ActionCategory 6, ActionId 16. This tells us Run is assigned to category-id 6-16.
I've done this for all the actions in the keybind menu. There are also actions for the mouse. Two actions are bound to left mouse, two to right mouse, and an action for each of the horizontal and vertical mouse axes. I uploaded a spreadsheet with what I found here[drive.google.com] for reference. I didn't take the time to figure out exactly what the unlabeled actions are, but they're probably not hard to figure out (Escape to cancel, Return to accept, for example).
Updating the XML to Add/Change a Bind
If I want to bind Run to mouse4, I can simply add an element to the mouse bindings xml. Noting that there are "buttonMaps" and "axisMaps" in the mouse xml, we'll add an ActionElementMap to the buttonMaps list.
<ActionElementMap> <actionCategoryId>6</actionCategoryId> <actionId>16</actionId> <elementType>1</elementType> <elementIdentifierId>6</elementIdentifierId> <axisRange>0</axisRange> <invert>false</invert> <axisContribution>0</axisContribution> <keyboardKeyCode>0</keyboardKeyCode> <modifierKey1>0</modifierKey1> <modifierKey2>0</modifierKey2> <modifierKey3>0</modifierKey3> <enabled>true</enabled> </ActionElementMap>
We copied the actionCategoryId (6) and actionId (16) from the values we got out of the keyboard defaults (found on the spreadsheet I created). Then we copied the elementType (1) and elementIdentifierId (7) from the Rewired mouse spreadsheet. Everything else is just copied from one of the other buttonMaps items.

If you just want to change a keybind (for example, change Jump to Enter), it's the same thing except modifying the existing key instead of adding a new one. Also, you'd do that one in the Keyboard xml, instead of the Mouse xml.
Merging the XML back into the Registry
  1. Remove all the extra whitespace. Turns out your mouse will stop working entirely if you don't. In Notepad++, you can replace all with the Regular Expression "\s" to "" (nothing). IMPORTANT: Select everything but the first two tags then replace all in the selection only. There are spaces in the xml tag and the MouseMap / KeyboardMap tags that need to be preserved. Just manually delete the newlines without replacing the whitespace inside the tags themselves.
  2. Convert from minified xml back to hexadecimal. We'll use the same website, http://www.unit-conversion.info/texttools/hexadecimal, making sure to select text to hex this time.
  3. This outputs space-delimited hexadecimal. We need to convert to comma-delimited. Paste the output back into Notepad++ and replace all with " " (space) to "," (comma). MAYBE IMPORTANT: Add ",00" to the end of the hex. This tells the parser it's reached the end of the file and might be critical depending on the parser. (The original hex ends with 00, so I suggest adding it back.)
  4. This goes into the original .reg file we exported from regedit. Find the key with hardwareIdentifier=Mouse then delete everything after "=hex:" up to the next key. In my case, that was the last key in the file, so there's just a blank line after it. (If you're editing the keyboard settings, then you'd edit the hardwareIdentifier=Keyboard key instead.)
  5. Now, paste the comma-delimited hex right after "=hex:".
  6. Save the registry file. Go back to where you saved it, and right-click then Merge it into the registry.
  7. Open the game and hope it worked.
Miscellaneous Notes
Thus far I've gotten the following to work successfully:
  • Binding Run to mouse4 as above.
  • I've swapped left and right mouse buttons by simply changing elementIdentifierId from 3 to 4 and vice versa.
  • I've also gotten mouse4 to behave like right mouse by adding new element values but using the actionCategory and Id from the existing values.
  • I then swapped from mouse4 to mouse5 by changing from elementId 6 to 7, showing that both side buttons work.
One thing I've noted is that actionCategoryId doesn't seem to matter. I initially made Run work with ActionCategory 0 instead of 6. And it seems to change depending on how the controls were changed. I haven't tested every single action in the spreadsheet to make sure it's correct, and I may have misread something when reading off the defaults. But it seems that you can just use 0 for the category and be fine.

To illustrate the weirdness: I changed the Save button from C to E in the in-game menu. Now, E is assigned to 2-17 (Take), 3-38 (Build), and 0-26 (Save). Save should be 2-26, but is instead listed in category 0.
Troubleshooting
The xml parser for Rewired seems to be very finicky. Try to get the xml as close to the original configuration as possible.

Also, make sure you didn't do something stupid. I forgot the opening tag for the ActionElementMap node, and it broke the entire parser. Generally, you'll know you're in the ballpark if the controls work. Otherwise, they'll completely break and nothing works, even the stuff that worked before.

If the controls work, but your binding doesn't, make sure you got the right element Id, that you're using element Id and not Action Id or KeyCode, etc.

If all else fails, go into the registry and delete the 4 keys starting with UserRemapping. The game will automatically revert to defaults when you restart it. Worst case scenario, delete the entire TheForest node. Just don't mess with anything outside the TheForest node because you can break things that way.
10 Comments
krrr Dec 22, 2024 @ 9:47am 
i managed to integrate the mapping for xbox360 controller model into the registry with this guide. Thanks alot. I mapped RB Button for toggle sprinting. Annoying when using left analog stick and have to press it to sprint. I had to keep format of the original exported reg-file very strictly. So i copied the hex-block of the according xml block i wanted to change and edited it in notepad++ (there you can download a HEX Editor plugin). Then i noticed the hex changes and to keep the original format as close as possible, i just edited the particular hex letters needed in the reg-file.
Shane Gooseman Sep 29, 2022 @ 12:19am 
Thanks for your very comprehensive answer! I will try it. Cross fingers I'm not to dumb. :papyruswacky:
fosley  [author] Sep 28, 2022 @ 9:13am 
(Comments on Steam sort newest on top, so you'll want to read the bottom comment first, then work your way up. Probably obvious.)
fosley  [author] Sep 28, 2022 @ 9:11am 
So you'd want to add an extra bind in the keyboard section of the XML to
<actionCategoryId>2</actionCategoryId>
<actionId>11</actionId>
<elementType>1</elementType>
<elementIdentifierId>1</elementIdentifierId>
<keyboardKeyCode>97</keyboardKeyCode>

or change from 2-11 to 4-37 if it's the other action. One action is related to clicking on 2D interface elements, while the other is related to actions in the game world, but I don't remember which is which. You'll also want to keep the other elements as listed in the guide (the axis, modifier, invert, enabled elements).

For setting right mouse to move forward, you'd need to change action 2-11 (or 4-37 if I got it wrong) in the mouse bindings. 'Forward' is Action category 6, Id 8, so you'd just change the 2 to 6 and the 11 to 8. That would unbind the Block action from the mouse, then bind the Forward action instead.
fosley  [author] Sep 28, 2022 @ 9:11am 
You can download a CSV file with all the Rewired key codes. There's one for keyboard setup, and one for mouse setup. There's also stuff for gamepads, but I didn't mess with those myself. The key 'A' is Type 0, Element ID 1, keycode 97. (But Type is set to 1 in this game for some reason, so you might just stick with that.)

The second set, which corresponds to the game action you're binding the key to, doesn't have an official list that I know of. I created a spreadsheet of all the known commands, which are just the ones created by default when you install the game. I uploaded the spreadsheet to my Google drive, here: https://drive.google.com/file/d/1F71Rlxwvpv2EGlfikhPrcvdjzlAvwIiV/view

Looking on that spreadsheet (noting there are two tabs, one for keyboard, one for mouse), you can see that 'Block' isn't labeled. However, I believe it falls under one of the actions assigned to Right Mouse. Either Action category 4, Id 37; or category 2, Id 11.
fosley  [author] Sep 28, 2022 @ 9:11am 
@ShaneGooseman
I haven't played The Forest in a while, so I'm not positive I remember the details precisely. It's a tedious process regardless, but hopefully I can help out.

Forewarning: you wouldn't be changing just the Block action. You'd be changing other stuff mapped to the right mouse button, such as cancelling a shot with the bow. The action exposed to the control scheme is basically just the "right mouse" action, which internally contains a bunch of other logic. It's possible the Block action has its own action ID, but I don't know what it is. You could try a bunch of different combinations and hope you get lucky, but it will be tedious.

There are two sets of numbers. One set, which corresponds to the key or button you're mapping to, is from the Rewired interface, and you can find them on the Rewired website, here: https://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action-keyboard
Shane Gooseman Sep 28, 2022 @ 3:35am 
I don't understand the Updating step. I don't know how you get the numbers you inserted and where you did it. I only want to bind right mouse button to move forward and block to a. With GlovePie I always block when moving. That's annoying and a shame for a game in 2022 not having free key binding ability.
ldrancer Jul 4, 2022 @ 3:34pm 
oh wow, saved off line because i dont trust them
fosley  [author] May 29, 2022 @ 4:14pm 
@SaneMan
Yeah, it's quite cumbersome for something that should be native, but I'm glad I could be of help to someone.
SaneMan May 29, 2022 @ 3:58am 
Great work, just purchased and it was the first thing I noticed was missing, mouse button rebinds (mouse4 as Run as it happens, along with others). It's unfortunate that this is the only method to sort this issue out and that the game devs still haven't provided this option natively.