Is there a way to bind a Minecraft command to a hotkey?

For example, I’d like a way to toggle between modes (survivla/creative) by pressing the Tab so that if I’m in a nasty pinch (like getting poisoned by a spider and being unable to fight back because the game suddenly lags really badly) and want to avoid losing a full inventory of valuables that I worked hard to get over the past five hours, I can quickly switch to creative mode.

I searched for a mod to do this and (surprisingly) came up empty; all I could find was the macro/keybind mod which requires LiteLoader and doesn’t seem to be able to bind arbitrary commands to keys.

The closest thing to a solution that I could find were suggestions to automate it with AutoHotkey, but that is no good because some keystrokes to get lost (probably due to the game’s CPU load), so pressing the hotkey will result in amemode 1 or /amemo 0 and such.

Is there a way to bind a command to a key so that it always works correctly?

  • 2
    You seem to have answered your own question - there's no way to do this natively. – dlras2 Nov 5 '13 at 15:38
  • 3
    You seem to have answered your own question @dlras2, wow, so you’re saying that my “google-fu” and research skills are perfect and flawless? Good to know. – Synetech Nov 5 '13 at 15:41
  • I believe the mod Single Player Commands allows binding arbitrary console commands to keys? Haven't used it, but I recall an old Nerd³ video demonstrating his custom keybinds, and I'm pretty sure he was using SPC. Maybe someone who has done it can answer from experience. – SevenSidedDie Nov 5 '13 at 16:05
  • @SevenSidedDie, yes I think I’ve seen that, unfortunately it has yet to be updated. I even tried using the latest version (for 1.6.2) anyway (on 1.6.4), but unlike some mods that work without having to be updated, this one doesn’t. Regardless, that’s a valid answer even if it doesn’t quite work (until it is updated), so if you want to write it as an answer, I’ll accept it for now. – Synetech Nov 5 '13 at 16:09
  • I would have to research it from scratch, since I know it takes some finicky config work but I don't already know the details. I'll let someone else have that rep. :) – SevenSidedDie Nov 5 '13 at 16:21

It seems that Single Player Commands has finally been updated to 1.6.4 (of course MC 1.7.2 is out now…)

With this, you can bind commands to keys as so:

/bind y gamemode 1

You can also use /bindid to set a special key via its key-code. It can’t quite do something like toggling (which would require knowing or keeping track of the current state), but it does let you bind a key to a macro (with the /macro command), so it might be possible to cobble together something that can toggle, but even if not, it’s still a perfectly suitable solution for most applications. (In the case of switching modes, Tab can be bound to creative mode to quickly avoid dying and then switching back to survival can be done with another key or manual.)

  • 1
    Nice! Aside, it may be possible (as was often done in the days of Quake) to bind a macro that runs the desired command then rebinds its own key to another macro that is the other half of the toggle (which then does the same rebinding trick to complete the toggle), in order to get a functional toggle key. – SevenSidedDie Nov 5 '13 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.