Advertisement

You're blocking ads, which pay for BlenderNation. Read about other ways to support us.

Remapping Keystrokes in Blender

36

autohotkey_logo.gifThe recent article about the keystroke tool for video tutorials spurred my curiosity about the AutoHotkey scripting language. Looking further, it quickly became clear that there might be a way to remap keystrokes in Blender. I performed a couple of quick tests...

My keystroke remaps worked flawlessly!

Now, I have absolutely no use for remapping keystrokes in Blender. But, there are clearly those in the community (or standing in the wings of the community) that desire such a thing. So, I thought that I would share my findings.

Fortunately, the open-source AutoHotkey application (Windows only) makes this about as easy as it can get. You'll have to read the documentation and study the examples but, here's the simple script that I created to remap the R-key to the S-key and the S-key to the R-key. The remapping is specific to the Blender application alone (that's what the first line of code does).

#IfWinActive ahk_class GHOST_WindowClass
r::s
s::r

This type of keystroke could easily get out of control if you get too crazy with it but, I think it will help ease the transition of some new users if they can remap a few keystrokes that they're more used to using.

I believe it's also possible to remap mouse buttons as well but, I haven't tested that capability.

Good Luck and I hope this helps some of you.

Links:

36 Comments

  1. Interesting, but one of the main reasons for having customisable keys is not just to be able to shuffle things around to different locations, but to have deeper control and set up your own keys for specific tools in your workflow. For example, I'd love to have a direct keypress for 'merge at center' without having to go through a menu.

  2. Tried myself remapping Blender with Autohotkey a year ago. But it was bit rough and not reliable when working fast. So I abandon it.

  3. @Matt
    I absolutely agree! That's why I stated that I personally don't have a need for them but, from the many forum discussion about remapping keystrokes, some people would really like to be able to remap a few keystrokes to their liking.

    I think the real value of remapping keystrokes, besides what you mentioned, is for projects like Elephants Dream where there are new tools being coded and artists may prefer different keystrokes to match their preferred workflow without having to have the new code adjusted.

  4. @RedSharky
    I've had no problems with testing it, yet. A year is a long time for many things to change, especially on a developing project like AutoHotkey. Also, the more you remap, the more problems you're likely to have due to criss-crossing keystrokes.

    One reason I wanted to post this is to help make the point that when Blender gets internal custom keymapping features, it won't turn out to be the missing link that some believe it will be for making a 3D application "easier" to use. You still will have to understand the workflow paradigm.

  5. @Matt

    "...I'd love to have a direct keypress for 'merge at center' without having to go through a menu."

    I would be surprised if you can't do this with AutoHotkey. It is a scripting language with very deep capabilities. Take a look at some of the things people have posted in their forum.

    You can even create custom mouse gestures that are application-specific!

  6. Just wondering but I suppose that if you map one key to another then it will happen to everything on windows. Is it possible to script it so that if the actual window that is open is named blender then the keys move around?

    (Im not really interested in swappink keys, but this suggestion if correct might help certain people)

  7. Sovereignncc-e on

    I wish that Blender worked like the GIMP did in this respect. In the GIMP with the proper setting enabled, you just highlight the function whose hotkey you want to change in a menu and press a key. The program then automatically maps the function to your new key! It could get slightly confusing, and it probably shouldn't get turned on by default (I could just see the posts on elysiun like "I CAN"T MOVE THINGS ANYMORE"), but this could be an easy, powerful method of customizing Blender to your taste/background.

  8. Anyway next version of blender will have that (or at least i heard its planned)

    It's windows-only, so not so much interesting for a cross-platform app like blender.

  9. AutoHotkey is a very powerful language. With it I've developed a lot of programs for everyday use(search for kiu in AutoHotkey forum) and it can help a lot your work by automating repetitive tasks, change hotkeys, map hotkeys to functions, change position and size of windows, etc. Also it can automate program specific commands, like "File->Open", but for blender this is more difficult cause blender has a different architecture and all subwindows and commands in blender are different from most of programs. So, for example, while is simple to associate to CTRL+1 the function "File->New Tab" in firefox, it's not so simple to associate the CTRL+1 hotkey with "Merge at center" in blender.

  10. Hey, Matt!!

    Try this:

    - Install AutoHotkey
    - Create a text file on your desktop with the following code:
    #IfWinActive ahk_class GHOST_WindowClass
    +m::Send, {ALTDOWN}m{ALTUP}3{ENTER}

    - Save it with an extension of .ahk (merge2center.ahk)
    - run the file
    - Guess what it does...

    Use Alt-M, in Blender, to merge selected vertices using the Center option.

  11. @Salvatore Agostino Romeo

    You're right, it's more difficult for Autohotkey to control non-mswindows apps like blender. But since you can do most things in blender using keystrokes, you can easily map a single keystroke like CTRL+1 to a sequence of keystrokes like ALT+M 1 to merge verts at center with:
    ^1::send !m1

    Btw. the author of Autohotkey has indeed changed the method of sending keystrokes a few month ago to increase its reliability.

  12. @Mats
    Don't forget the code:

    #IfWinActive ahk_class GHOST_WindowClass

    This way the script will only be in use when the Blender window is the active window.

  13. @Kernon

    Yep, thanks! I forgot.

    Here's another nice trick that is not so well known:
    In case you run out of free hotkeys, you can redefine any key as a prefix key. This way you can use for example the escape key to combine it (just like shift or alt) with another key to perform some action WITHOUT losing the original behaviour of the escape key. This is not limited to the escape key of course, but it's a good choice because it's so easy to reach.

    Example:
    #IfWinActive ahk_class GHOST_WindowClass ; Hi Kernon :-)
    ESC & 1::send !m1
    ESC::send {ESC}

    So, if you press ESC and release it: blender simply receives the ESC keystroke.
    If you hold down ESC and press 1, blender receives ALT+M 1 (and no ESC keystroke!)

  14. I have been using AutoHotKey with Blender for a while now. I have a Nostromo Gamepad by Belkin, and use AutoHotKey to reassign all my gamepad buttons for use in Blender. So my left hand is on the gamepad while I use my right hand for the mouse or wacom tablet.
    Using AutoHotKey also allowed me to make and use custom menus which I can open by pressing the assigned gamepad button.

  15. @Mats
    Very cool! I didn't know that. There's so many ways to use this tool, it really takes some creativity and experimentation...kinda like Blender.

    @Joel
    Sounds very interesting. Do you have the gamepad mounted to keep it stationary?

    I'm seriously thinking about getting a USB Numpad so I can place it to the left of the keyboard. That way, I don't have to reach across over the keyboard and/or take my hand away from the mouse.

    The custom menus and dialogs capability are interesting as well. There was an example in the forum for adding a custom toolbar with icons to any application. I was able to add an actual toolbar within the Blender window! I had just started looking into AutoHotkey so, at the time, I didn't know how to edit the script to send commands and macros to Blender. I'll have to revisit that one later.

  16. The Nostromo gamepad is not a joystick, it works the same way as the numpad you described. I can reach any button on the pad with my fingers without moving my hand.

  17. I know this is cheeky, and lazy, but can anyone supply me with the code to make it think I'm pressing the numical '.'? I use a laptop with a 'virtual' numerical pad and find it an incredible chore to simply focus the viewport on my selected object :l It's so much easier at work on a normal keyboard, if I could do it at home I would be very very happy!
    PS, I *am* on the way to the site to find out for myself, but thought I could save myself some reading if someone already knows how to do this :D
    Thanks...
    PPS, how about one for keyboard shortcuts to vert, edge and face mode? Please?! I'm sure we would all find this useful! I suppose the above ALT M code could be adapted to do this?

  18. @Joel:
    That looks a lot more comfortable than what I was thinking about and, it can programmed. Gotta have one, not just for Blender but everything.

  19. Wow, that was easy, my life has just improved considerably!! :D

    #IfWinActive ahk_class GHOST_WindowClass
    ^1::Send, ^{TAB}1{ENTER}
    ^2::Send, ^{TAB}2{ENTER}
    ^3::Send, ^{TAB}3{ENTER}

    CTRL 1, 2 or 3 will now go to verts, edges or face.
    Beauty!
    Now for the numpad.....

  20. Thanks for having such faith! I got the numpad sorted too, but have been debating wether to post it or not, as it's a little specific to my preferences, but while I'm here, I might as well!....

    Lwin::NumpadDot
    Rwin::^
    #IfWinActive ahk_class GHOST_WindowClass
    ^1::Send, ^{TAB}1{ENTER}
    ^2::Send, ^{TAB}2{ENTER}
    ^3::Send, ^{TAB}3{ENTER}

    So, the first two lines should always map my windows key to the numpad dot and the right windows to ctrl. Sound wierd? Well, I've always detested the windows keys, they seem to be magnetic, always popping up when you didn't mean to press it, so until now I've been using KeyTweak to completely disable the left one, and turn the right one into a regular CTRL - this is great for Photoshop zooming, because the laptop doesn't have a CTRL on the right side of the keyboard.
    Anyway, I'll now be uninstalling KeyTweak, and using AHK means that my Windows key can now be revived and used as a Blender ONLY key!! Ace ;]
    Thanks so much for the link Kernon.

  21. Hi all !

    Here is the script I use to start blender on Linux. It allows French users to use layer shortcuts with a French "AZERTY" layout keyboard.
    It also ask SDL to use ALSA for the sound system, and start blender in windowed mode.
    It put the keyboard back in original fr-latin9 state when blender quit.

    ----------------- blender.sh start -----------------
    #!/bin/bash
    xkbcomp - $DISPLAY { [ grave, asciitilde, twosuperior, notsign ] };
    key { [ 1, ampersand, dead_acute, periodcentered ] };
    key { [ 2, eacute, asciitilde, Eacute ] };
    key { [ 3, quotedbl, numbersign, cedilla ] };
    key { [ 4, apostrophe, braceleft, acute ] };
    key { [ 5, parenleft, bracketleft, diaeresis ] };
    key { [ 6, minus, bar, brokenbar ] };
    key { [ 7, egrave, dead_grave, Egrave ] };
    key { [ 8, underscore, backslash, macron ] };
    key { [ 9, ccedilla, asciicircum, Ccedilla ] };
    key { [ 0, agrave, at, Agrave ] };
    };
    };
    EOF

    SDL_AUDIODRIVER=alsa AUDIODEV=default blender -w $*

    setxkbmap -model pc105 -layout fr-latin9

    ----------------- blender.sh end -----------------

    You may adapt it to your needs and country. Have a look to 'man xkbcomp' and files in /usr/share/keymaps/i386 for more info on keyboard remapping with X.

    Regards

    Edouard

  22. This could be a cool way to have pre-configured scripts for Maya, Max, etc. users to help them transition over to Blender.

  23. Sorry, seems I got the wrong key, can anyone tell me what AutoHotKey calls the 'right click' key, just to the right of the Right Windows key? The one with the pointer and menu? Turns out I need that one - I don't even have a Right Windows, thankfully!
    Thanks
    Wayne

  24. I'm not sure but, look in the AutoHotkey Start Menu folder and find the macro recording tool. You can record whatever keystrokes and then see the code created. That ought to tell you what you need.

  25. Just learn the damn hotkeys.... is that so hard?
    I know the hotkeys for 3ds max, maya, xsi, photoshop, gimp, painter, zbrush, mudbox and the list goes on ...oh... and let's not forget blender...

  26. The problem i'm having is that i could previously undo in editmode with a single keystroke, which was U. How it's Ctrl-Z, however on my German keyboard the Z is in the top middle of the keyboard! There is no way i can type that with a single hand, considering my hands are rather small.

    I'd like the two buttons Z and Y simply interchanged for hotkeys so that it works like a US keyboard, however with them not being interchanged when entering text. And since i use Blender on different computers and OS, the solution should better depend on Blender only.

    In fact, i can see how useful a full-fledged hotkey editor would be. One could automate most frequently called functions from multi-tap stroked down to single-tap, and it would show one where possible collisions lie.

  27. Wow, this is quite an old post... anyway...

    I just ran into this whole autohotkey stuff and found it fascinating. I was able to, quite easily, remap keys and assign already created shortcuts in blender to specific keys on a second keyboard. The thing is, I want to assign a key to a specific python function... for example: use Numpad0 to select checkerselect (bpy.ops.mesh.select.nth()), since it doesn't have a shortcut assigned to it in blender.

    I know I could just assign a shortcut to it and I actually did that, but ended up messing up something else. So rather than messing up blender's default keyboard shortcuts, I want to assign certain functions/actions to keys on a second keyboard.

    How would I be able to achieve this?

Leave A Reply

To add a profile picture to your message, register your email address with Gravatar.com. To protect your email address, create an account on BlenderNation and log in when posting a message.

Advertisement

×