Last active
March 18, 2021 16:41
-
-
Save connordavenport/f9c3b571acc37f10a655e1be6d34fe6c to your computer and use it in GitHub Desktop.
Convert arrow functions to ASWD keys in the glyphView. If you have shortcuts already set up for any of these keys you will run into issues!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vanilla import FloatingWindow | |
from mojo.events import addObserver, extractNSEvent | |
class WASDTool: | |
def __init__(self): | |
addObserver(self, "keyWasPressed", "keyDown") | |
def keyWasPressed(self, info): | |
glyph = info["glyph"] | |
if glyph: | |
event = info["event"] | |
characters = event.characters() | |
shiftDown = extractNSEvent(info)['shiftDown'] | |
commandDown = extractNSEvent(info)['commandDown'] | |
x = 1 | |
if shiftDown: | |
x = 5 | |
if commandDown: | |
x = 100 | |
KEYMAPPING = { | |
"w":(0,x), | |
"a":(-x,0), | |
"s":(0,-x), | |
"d":(x,0), | |
} | |
objects = [] | |
objects.extend(glyph.selectedBPoints) | |
objects.extend([p for p in glyph.selectedPoints if p.type == "offcurve"]) | |
objects.extend(glyph.selectedComponents) | |
objects.extend(glyph.selectedAnchors) | |
if objects != []: | |
# convert to lowercase so we dont have to use a huge dict | |
if characters.lower() in KEYMAPPING.keys(): | |
move = KEYMAPPING[characters.lower()] | |
if move: | |
glyph.prepareUndo("movePoints") | |
for obj in objects: | |
obj.moveBy(move) | |
glyph.changed() | |
glyph.performUndo() | |
WASDTool() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment