I updated it based on @frederik's comments and added a few objects:
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()