Screencast keys status tool

Read the error message!!!
set a # in front of the offending line!

Edit: oh you have already a good version , sorry.

For Blender 2.55:

space_view3d_screencast_keys.py

# Original Script by: Paulo Gomes 
# Contact: [email protected] 
#  
# Contributor(s): Bart Crouch 
# 
# Tested with r33563 
# 
# ##### BEGIN GPL LICENSE BLOCK ##### 
# 
#  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 LICENSE BLOCK ##### 
 
 
import bpy 
import bgl 
import blf 
import time 
 
 
# information for the add-ons window 
bl_addon_info = { 
    'name': '3D View:Screencast Key Status Tool', 
    'author': 'Paulo Gomes', 
    'version': (0,4), 
    'blender': (2, 5, 5), 
    'location': 'View3D > Spacebar > Search for "Screencast Key Status Tool"', 
    'description': 'Display keys pressed in the 3d-view, useful for screencasts.', 
    'warning': '', 
    'wiki_url': '', 
    'tracker_url': '', 
    'category': '3D View'} 
 
 
 
def draw_callback_px(self, context): 
    # draw text in the 3d-view 
    blf.size(0, 20, 72) 
    final = 0 
 
    # only display key-presses of last 2 seconds 
    for i in range(len(self.key)): 
        if time.time()-self.time[i] < 2: 
            blf.position(0, 15, 70+20*i, 0) 
            blf.draw(0, self.key[i]) 
            final = i 
        else: 
            break 
 
    # get rid of statuses that aren't displayed anymore 
    self.key = self.key[:final+1] 
    self.time = self.time[:final+1] 
     
 
class ScreencastKeysStatus(bpy.types.Operator): 
    '''Draw keys pressed in 3DView''' 
    bl_idname = 'view3d.screencast_keys' 
    bl_label = 'Screencast Key Status Tool' 
 
    def modal(self, context, event): 
        context.area.tag_redraw() 
 
        # keys that shouldn't show up in the 3d-view 
        ignore_keys = ['LEFT_SHIFT', 'RIGHT_SHIFT', 'LEFT_ALT', 'RIGHT_ALT',  
        'LEFT_CTRL', 'RIGHT_CTRL','TIMER', 'MOUSEMOVE', 'MIDDLEMOUSE', 
        'LEFTMOUSE', 'RIGHTMOUSE', 'WHEELDOWNMOUSE', 'WHEELUPMOUSE',  
        'NONE'] 
 
        if event.value == 'PRESS': 
            # add key-press to display-list 
            sc_keys = [] 
             
            if event.shift: 
                sc_keys.append('Shift ') 
         
            if event.alt: 
                sc_keys.append('Alt ') 
         
            if event.ctrl: 
                sc_keys.append('Ctrl ') 
 
            if event.type not in ignore_keys: 
                sc_keys.append(event.type) 
             
                self.key.insert(0, '+ '.join(map(str, sc_keys))) 
                self.time.insert(0, time.time()) 
 
        if event.type == ('F7'): 
            # stop script 
            context.region.callback_remove(self._handle) 
            return {'CANCELLED'} 
 
        return {'PASS_THROUGH'} 
 
    def invoke(self, context, event): 
        if context.area.type == 'VIEW_3D': 
            # start script 
            context.window_manager.modal_handler_add(self) 
 
            self._handle = context.region.callback_add(draw_callback_px, (self, context), 'POST_PIXEL') 
            self.key = [] 
            self.time = [] 
       
            return {'RUNNING_MODAL'} 
 
        else: 
            # operator not invoked from within the 3d-view 
            self.report({'WARNING'}, 'View3D not found, cannot run operator') 
            return {'CANCELLED'} 
 
def register(): 
    pass 
 
def unregister(): 
    pass 
 
if __name__ == '__main__': 
    register()

Does not work in the latest Blender of yesterday (W32 Vista)
See:
>>> dir(bpy.context.window_manager)
[‘doc’, ‘module’, ‘slots’, ‘add_fileselect’, ‘add_modal_handler’, ‘animation_data_clear’, ‘animation_data_create’, ‘bl_rna’, ‘clipboard’, ‘copy’, ‘invoke_confirm’, ‘invoke_popup’, ‘invoke_props_dialog’, ‘invoke_props_popup’, ‘invoke_search_popup’, ‘keyconfigs’, ‘library’, ‘name’, ‘operators’, ‘rna_type’, ‘tag’, ‘use_fake_user’, ‘user_clear’, ‘users’, ‘windows’]

>>>

and the message:
Traceback (most recent call last):
File “Text”, line 110, in invoke
AttributeError: ‘WindowManager’ object has no attribute ‘modal_handler_add’

EDIT: I see
it is add_modal_handler :wink:

Yes, post 42 has the new code for 2.55.
I see they are continually renaming functions that way, it is because it is more easy to remember to have all in the same way and blender code is huuuuge.

I am trying understand things and you can spend hours and hours and do not find yet how the hell things are done. For example only recently I could understand the menus are not in the C code but are external python scripts (probably to people be able to modify them to their pleasure).
I understand now also why in the menus there is select border, and select circle but there is not select lasso. It doesn’t works because it starts to select lasso from the menu. This brings a situation I don’t like: there are options that are only accessible on shortcuts but not in menus. I don’t like that in any app.

hy - cool script - i followed the instructions carefully - but get that ERROR with official 2.55 when i click on “Screencast key Status Tool”

AttributeError: ‘WindowManager’ object has no attribute ‘modal_handler_add’
Traceback (most recent call last):
File “Text”, line 110, in invoke
AttributeError: ‘WindowManager’ object has no attribute ‘modal_handler_add’

I have checked and it is working. Are you using the script in post 42?

yeah from #42 (i double checked it)

  • i have named i “space_view3d_screencast_keys.py”
  • copy´ed the file to addons dir
  • enabled it
  • space > search > klick on it

got the same error

Do i have to install a special python version ? (i got this bundled py message at startup)
i just have python for the “old” blender installed…
maybe this is wrong ??

thx for helping

greetings
tobi

It is not a plugin to add to any folder.

Open a text window. Add a new text and copy paste the script text. Run the script clicking on the Run script button below.

Now as it is said in the script:
View3D > Spacebar > Search for “Screencast Key Status Tool”

and start to press keyboard and it will show

Read the way it is used in the “location” line in the code (line 39 I think)

Tell me the version of blender you are using and the exactly steps you do if it doesn’t work.

(Answering a private message about it don’t working: )
I will upload a video. Give me some time.

Yes, the thread is the right place, you´re right :wink:
i´m pretty sure that i´ve done everthing right with the script, but a video-demo can make it clear.
thx, tobi

In the video I am using Blender 2.55 build 33684

Download the video at 720 HD and use VLC in half speed (0.5x) to see it at real time. :yes:
At the end of the video the script is not able to show the keys I use to lasso select vertices so it is not perfect. But a great work of Paulo Gomes as it is at the moment!!!

ok, but i´m using 2.55 OFFICIAL (build r32738) like i said before… so okay - thats the point !

is this an official release - i ask this because i dont want to work with a release that maybe has features that are not official (to avoid confusion)
if it is official - where can i get it - and how i know it is an offical release - not a testing one ?

and how can i tell this to blender-newbies in my tutorials - it seems very confusing with all this (test)releases?
is there a save (not testing) line of build i can easyly follow without worry to run in an unofficial directon?
just wanna keep it straight as a user and trainer.

if one can answer this question maybe i´m a step closer to the truth of the new blender and development in generall

thank you for helping and sharing :wink:
good night
tobi

Except Bmesh builds all the rest is just the “official” build with added things that will not make your blend files incompatible with future official releases. Bmesh uses a different way of meshes so any build that don’t have bmesh code would be unable to read it.

There are a lot of bug fixes from the release you are using so I really recommend you download one from graphicall. Just don’t use the addons they usually have installed and you are sticking to “official”.

hi all, i’ve changed the script a little, i’ve added a menu in the properties panel display tab.

Link to wiki

Link to script

activate the script:

  • Put the script in \.blender\scripts\addons.
  • In user preferences you can see the Add-Ons menu.
  • You can activate the script here.
  • The script will now show up in the properties panel of the 3d view in the Display tab.

what buttons do:

  • ‘Screencast Keys Status’ activates/deactivates script.
  • ‘Pos x’ ‘Pos y’ Position of the text.
  • ‘Size’ Size of the font.
  • ‘Mouse’ Activates/Deactivates display of mouse events.

Thanks Bao2 for the updates in the script.

Thanx Paulo!
I tested it recently and i must say that this tool must be in the trunk! definetely!

bohr as we Germans would say in my local slang

a cool example to show the benefit of the new python driven interface

Thanks Paulo it is much better now in 3DView properties panel. I just don’t understand why this feature of showing the keys that are pressed is not in the C code of blender and continues to be a external script. And it is the most important script in the addons folder in my opinion.

I use it with these changes:
in ignore_keys list I added ‘NONE’
Size default to 40
Pos Y default to 70
‘name’: ‘Screencast Key Status Tool’ (deleting “3DView:” )

Hi Paulo, i made a mod of your ui with extra start and stop Buttons for the screencast…

http://img263.imageshack.us/img263/541/scast.png

What do you and the others think?

The first button “Screencast keys Status” is the start/stop button. So I think that would be a duplicate.
I think it would be better change the text of the button “Screencast Keys Status” to “START Screencast” by default. Thento when pressed to run change the button text to “STOP Screencast”. And again when pressed to stop change to “START Screencast”.