[Bf-python] WIP: Displaying Keypresses for VideoTuts

Joe Eagar joeedh at gmail.com
Thu Nov 15 02:06:36 CET 2007


Cool, I'll have to try it when I have time.

And btw, why are you doing

 Blender.Draw.Text("%s" % keystring,"large")?

"%s" % keystring is unnecessary, you should be able to simply pass it keystring.

Joe

Carsten Wartmann wrote:
> Hi,
>
> I wrote (still working on it) two space andler scripts for showing the 
> keys I press during presentations or for video tutorials.
>
> There are some quirks left (some I guess are a Blender limitation, some 
> are my bad python skills) but I think it is still usefull.
>
> You have to activate both handlers in the View->Space Handler Scripts menu.
>
> Maybe this idea is worth a consideration to include it into 2.50 (for 
> the self running tutorials).
>
> C&C welcome!
>
> Best Regards,
> Carsten
>
>
> Let the code talk:
>
> ------------------------------------------------------------------------
> # SPACEHANDLER.VIEW3D.EVENT
> #
> # 2007 Carsten Wartmann
> #
> # The space handler scripts ShowKeys and DrawKeys are showing
> # the actual pressed keys in the 3D View.
> #
> # This is usefull for presentations or video tutorials where the
> # key-combinations
> # will give some hints whats going on beside the narration.
> #
> # To use activate the handlers in the View->Space Handler Scripts memu
> # The display will be for the 3DView only and need to activated for
> # every
> # 3DView you like to see the keypresses.
>
>
> """
> Problems/Todo
>
> * Tab and Space not showing
> * some functions CTRL-Q, CTRL-W etc. not showing
> * while in Transformation (GSR) the script gets no events
> * B-B combination (Circle Select) not handled, maybe do the same for A-A?
>
> """
>
>
> import Blender
> from Blender import Draw
> import string
>
> try:
>      Blender.odo = Blender.odo + 0
> except:
>      Blender.odo = 0
>
> def Compose(key):
>      q = Blender.Window.GetKeyQualifiers()
>      quali = ""
>      if q & 3:
>          quali = "Shift+"
>      if q & 12:
>          quali = quali + "Alt+"
>      if q & 48:
>          quali = quali + "Strg+"
> # english language uncomment next line
> #        quali = quali + "Ctrl+"
>
>      Blender.keypress = quali+key
>      Blender.odo=0
>      Blender.Redraw()
>
>
> evt = Blender.event
>
> # a-z
> if (evt >= Draw.AKEY and evt <= Draw.ZKEY):
>      Compose(string.upper(chr(evt)))
>
> # function keys
> if (evt >= Draw.F3KEY and evt <= Draw.F11KEY):
>      Compose("F"+str(evt-303+4))
>
> # number keys
> if (evt >= Draw.ZEROKEY and evt <= Draw.NINEKEY):
>      Compose(str(evt-48))
>
> elif evt==Draw.ESCKEY:
>      Compose("Esc")
>
> elif evt==Draw.TABKEY:
>      Compose("Tab")
>      # doesnt work... Workaround below
>
> elif evt == Draw.LEFTMOUSE:
>      Compose("LMB")
> elif evt == Draw.MIDDLEMOUSE:
>      Compose("MMB")
> elif evt == Draw.RIGHTMOUSE:
>      Compose("RMB")
>
> # there must be a better solution, CTRL+PAD not working
> elif evt == Draw.PAD7:
>      Compose("PAD7")
> elif evt == Draw.PAD1:
>      Compose("PAD1")
> elif evt == Draw.PAD3:
>      Compose("PAD3")
> elif evt == Draw.PAD5:
>      Compose("PAD5")
>
> # clear keyfield after some mouse movements
> elif evt==4:
>      Blender.odo = Blender.odo + 1
>      if Blender.odo>100:
>          Compose("")
>
> # some testing/debugging lines
> #print dir(Draw)
> #print evt, Draw.ZEROKEY
>
> # ***** BEGIN GPL LICENSE BLOCK *****
> #
> # Copyright (C) 2007: Carsten Wartmann
> #
> # This program is free software; you can redistribute it and/or modify
> # it under the terms of the GNU General Public License as published by
> # the Free Software Foundation; either version 2 of the License,
> # or (at your option) any later version.
> #
> # This program is distributed in the hope that it will be useful,
> # but WITHOUT ANY WARRANTY; without even the implied warranty of
> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
> # GNU General Public License for more details.
> #
> # You should have received a copy of the GNU General Public License
> # along with this program; if not, write to the Free Software Foundation,
> # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> #
> # ***** END GPL LICENCE BLOCK *****
>
>
>
> ---------------------------------------------------------------------------
> # SPACEHANDLER.VIEW3D.DRAW
> #
> # 2007 Carsten Wartmann
> #
> # The space handler scripts ShowKeys and DrawKeys are showing
> # the actual pressed keys in the 3D View.
> #
> # This is usefull for presentations or video tutorials where the
> # key-combinations
> # will give some hints whats going on beside the narration.
> #
> # To use activate the handlers in the View->Space Handler Scripts memu
> # The display will be for the 3DView only and need to activated for
> # every
> # 3DView you like to see the keypresses.
>
>
> import Blender
> from Blender import BGL
>
>
> def StatusDraw(keystring):
>      if keystring<>"":
>          BGL.glMatrixMode(BGL.GL_MODELVIEW)
>          BGL.glPushMatrix()
>          BGL.glLoadIdentity()
>
>          wsx,wsy = Blender.Window.GetAreaSize()
>          len = Blender.Draw.GetStringWidth(keystring,"large")
>          Blender.BGL.glColor3f(0.8,0.8,0.8)
>          Blender.BGL.glRecti(wsx-len-10, 5,wsx-4, 27)
>          Blender.BGL.glColor3f(0,0,0)
>          Blender.BGL.glRasterPos2i(wsx-len-10+3, 11)
>          Blender.Draw.Text("%s" % keystring,"large")
>
>          BGL.glMatrixMode(BGL.GL_MODELVIEW)
>          BGL.glPopMatrix()
>
>
>
>
> StatusDraw(Blender.keypress)
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
>   




More information about the Bf-python mailing list