If you've been playing the awesome new co-op game Helldivers 2, you'll be familiar with the "stratagem" gameplay mechanic in which you summon various weaponry from airborne and satellite craft. This mechanic requires you to hold down a key/button to activate the stratagem input mode, while entering a sequence of directional key input.
Often during the game I tend to get overstimulated in the middle of a heated battle and my mind goes completely blank when trying to recall the one of the myriad codes I need to use to summon the effect I want. Even though the game UI displays them, it's still pretty hectic to precisely enter the sometimes lengthy codes when a giant scorpion is trying to rip my head off. To help spread liberty and democracy in the most efficient way possible, I thought I'd try to see if I could set up some stratagem macros using the awesome MACROPAD Hotkeys project from Phillip Burgess. NOTE: For simplicity, this particular setup mimics keyboard input, so until I hear otherwise I'm assuming this only works on the PC version of Helldivers II.
Custom Code
It took a few tries to figure out how to set up the macros so that the game would consistently accept them. Thankfully, the MACROPAD Hotkeys project is incredibly versatile and I was able to do this using the built-in features of the project without having to modify any of the core code. The main factors involved in getting this to work seemed to be:
- After pressing the stratagem input button, a significant delay was needed before the game would accept the directional input. I'm assuming this is due to needing to wait for the UI to fully present in-game before allowing further input. With experimentation it seems like the smallest delay possible is about 0.4 seconds.
- Each directional key needed to be pressed for a certain duration. The smallest duration I've tried for this so far is 0.05 seconds.
- A small delay is needed after each direction key is released. The smallest duration I've tried for this so far is 0.05 seconds.
In the /macros folder on my macropad CIRCUITPY drive, I created a new file named helldivers-2.py. Since I anticipate changing this file frequently as I progress through the game, I wanted to make it as simple as I could to add/edit new macros, so that I could even edit them in real-time as I played the game. To make this a little easier, I wrote a bit of custom code at the top of the file.
from adafruit_hid.keycode import Keycode # 1 START_INPUT_DELAY = 0.4 KEY_DELAY = 0.05 #2 START_INPUT = Keycode.CONTROL UP = Keycode.W DOWN = Keycode.S LEFT = Keycode.A RIGHT = Keycode.D #3 def stratagem(*argv): keys = [START_INPUT, START_INPUT_DELAY] for key in argv: keys += [key, KEY_DELAY, -key, KEY_DELAY] return keys
Custom Code Explanation
- Set up constants for the delays I'll be using
- START_INPUT_DELAY: Delay after pressing the key to initiate stratagem code input.
- KEY_DELAY: Delay after each direction key is pressed and released.
- Set up simple aliases for the keyboard keys that the game uses for stratagem input
- START_INPUT: Alias for the key that initiates stratagem code entry.
- UP/DOWN/LEFT/RIGHT: Aliases for the 4 directional keys used to enter the code.
- Wrote stratagem(*argv) function to make defining the macros easier. The first thing this function does is create a list with the START_INPUT key, and delays for START_INPUT_DELAY duration. Then, for each key in the combo, it appends entries to the list to press each direction key, wait a small bit, release each direction key, and wait a small bit more. Note that I'm omitting releasing the START_INPUT key because the core code will take care of releasing any still-pressed keys in the sequence when complete.
Full hotkeys code
With that, I am able to easily create and change hotkey sequences. The full CircuitPython 8 source of my helldivers-2.py hotkey file is below. If you want to use it as a template you'll need to set up your macropad to use the MACROPAD Hotkeys project, and then drop the helldivers-2.py file in the /macros folder. Note that the keys used are the default key assignments for the game, so if you've changed your in-game mappings, you'll need to update the aliases.
# MACROPAD Hotkeys: Helldiver II from adafruit_hid.keycode import Keycode START_INPUT_DELAY = 0.4 KEY_DELAY = 0.05 START_INPUT = Keycode.CONTROL UP = Keycode.W DOWN = Keycode.S LEFT = Keycode.A RIGHT = Keycode.D def stratagem(*argv): keys = [START_INPUT, START_INPUT_DELAY] for key in argv: keys += [key, KEY_DELAY, -key, KEY_DELAY] return keys app = { 'name' : 'Helldivers II', 'macros' : [ # COLOR LABEL KEY SEQUENCE # 1st row ---------- (0x000020, 'M-GUN', stratagem(DOWN, LEFT, DOWN, UP, RIGHT)), (0x000000, '', []), (0x000000, '', []), # 2nd row ---------- (0x200000, 'Prec', stratagem(RIGHT, RIGHT, UP)), (0x200000, 'Gat', stratagem(RIGHT, DOWN, LEFT, UP, UP)), (0x000000, '', []), # 3rd row ---------- (0x000000, '', []), (0x000000, '', []), (0x302000, 'Nape', stratagem(UP, RIGHT, DOWN, UP)), # 4th row ---------- (0x202000, 'Resup', stratagem(DOWN, DOWN, UP, RIGHT)), (0x002000, 'SOS', stratagem(UP, DOWN, RIGHT, UP)), (0x002000, 'Reinf', stratagem(UP, DOWN, RIGHT, LEFT, UP)), # Encoder button --- (0x000000, '', []), ] }