[Bf-python] Space handler script links

Willian Padovani Germano wgermano at ig.com.br
Tue May 10 04:50:55 CEST 2005


Hi,

I have to send 3 emails to give a simple answer ... not my best moment : ).

Campbell Barton wrote:

> Willian, this is the part thats not working. Blender.event is None, Im 
> not trying to set it, Im juts trying to print Blender.event whenever a 
> key is hit. and its printing a blank line.
>
>> BTW, not related to space handlers: your Python console script can 
>> access Blender.event in your gui's event() callback (registered with 
>> Draw.Register) to get the ascii value, this was in the commit, too.
>
This should work:

import Blender
from Blender import Draw

def gui():
    pass

def event(e, val):
    if val:
        ascii = Blender.event
        if ascii: print e, ascii, chr(ascii)
        if e == Draw.QKEY: Draw.Exit()

Draw.Register(gui, event, None)

# ---

Note two things: 1) only in the event callback Blender.event is the 
ascii value (if event has a printable value), otherwise it is "" as 
always except on slinks;  2) both key presses and releases are passed to 
the callback, better filter to get only presses and you should check 
validity of ascii value.

Again, sorry for the confusion.  My grandfather told me when I was a kid 
that eveyday we have a moment of stupidity and we are lucky if it 
doesn't happen while we're crossing a street or doing any other 
potentially dangerous thing.  These moments don't seem to happen 
everyday, really, but today I was replying your email during it...

-- 
Willian




More information about the Bf-python mailing list