How to get a keyCode in plugin?

Hey,

I tried figuring out how to detect when the space bar is pressed in the editor view. I seen other topics about key press, but couldn’t really get far.

Trying to access the NSEvent.keyCode I only get:

<unbound native-selector keyCode in NSEvent>

Any way of generally detecting space bar press, or more on point, disable drawing via drawBackgroundForLayer when space is pressed?

Cheers,
Johannes

You need to add parenthesis for all properties in objC objects.

NSEvent.keyCode()

You can do this:

currentController = self.controller.view().window().windowController()
if currentController:
	if currentController.SpaceKey():
		print "Space pressed"
	else:
		print "NO Space"

Thanks!

Are all attributes returned by dir(somePyObjIknowNothingAbout) always going to be methods?

Yes, all objC objects will only have methods. That is the main reason that we made a wrapper to remove them to not annoy the python folks.