Laptop Numpad Script

For months I have been frustrated by my SonyVAIO inability to allow a USB numpad to coexist with a full QWERTY keyboard map. Then along came Ray Badstibner (AKA raymaxbad) who inspited me with his BpKeyboard.py script. I adapted his work to create the Laptop Numpad Script.

Save it as LapTopNumPad.py
Thanks,
Trevor Noble

#!BPY

“”"
Name: ‘LapTopNumPad’
Blender: 241
Group: ‘System’
Tooltip: ‘Virtual Laptop Numpad’
“”"

author = “Trevor Noble”
version = “0.0.1”

bpydoc = “”"
LapTopNumPad.py 0.0.1

This script allows easy blending on laptops that do not support a USB numpad to co-exist with a fully QWERTY keybord such (e.g. Sony VAIO).

Use SHIFT and CTRL keys modifiers as with a normal Num Pad.

Thanks to Ray Badstibner (AKA raymaxbad) for creating the BpKeyboard.py script which I canabalised.

“”"

#--------import modules--------
import Blender
from Blender import Window, Text, Draw, BGL
from Blender.Window import *
from Blender.Text import *
from Blender.Draw import *
from Blender.BGL import *

#--------do it--------
def go_short():
QHandle(id)
Window.RedrawAll()

#--------get 3d window--------
try: # get 3d area
area = Window.GetScreenInfo(Window.Types.VIEW3D, rect=‘total’)
id = area[0][‘id’] # get the first view id

except: # get text area
area = Window.GetScreenInfo(Window.Types.TEXT)
id = area[1][‘id’] # get the second text id

#--------create buttons--------
def draw():
global PushButton15, PushButton16, PushButton17, PushButton18, PushButton19, PushButton20, PushButton21, PushButton22, PushButton24, PushButton25, PushButton26
glClearColor(0.000, 0.000, 0.000, 0.0)
glClear(GL_COLOR_BUFFER_BIT)

PushButton(‘Top’, 21, 2, 250, 60, 20, ‘+SHIFT Bottom View’)
PushButton(‘Front’, 15, 2, 225, 60, 20, ‘+SHIFT Back View’)
PushButton(‘Right’, 17, 2, 200, 60, 20, ‘+SHIFT Left View’)
PushButton(‘8’, 22, 23, 171, 20, 20, ‘Tilt Up’)
PushButton(‘4’, 18, 2, 150, 20, 20, ‘Pan <’)
PushButton(‘5’, 19, 23, 150, 20, 20, ‘Ortho / Persp’)
PushButton(‘6’, 20, 44, 150, 20, 20, ‘Pan >’)
PushButton(‘2’, 16, 23, 130, 20, 20, ‘Tilt Down’)
PushButton(‘0’, 24, 2, 100, 20, 20, ‘Camera’)
PushButton(’-’, 25, 23, 100, 20, 20, ‘Plus’)
PushButton(’+’, 26, 44, 100, 20, 20, ‘Minus’)

#--------exit function--------
def event(evt, val):
if (evt== QKEY and not val):
SetKeyQualifiers(0)
Exit()

#--------button events--------
def bevent(evt):
global letter
if evt == 69: #DelKey
QAdd(id, DELKEY, 1)
QAdd(id, DELKEY, 0)
go_short()

elif evt == 10: #EscPushButton
Exit()

elif evt == 15: #1PushButton
QAdd(id, PAD1, 1)
QAdd(id, PAD1, 0)
go_short()

elif evt == 16: #2PushButton
QAdd(id, PAD2, 1)
QAdd(id, PAD2, 0)
go_short()

elif evt == 17: #3PushButton
QAdd(id, PAD3, 1)
QAdd(id, PAD3, 0)
go_short()

elif evt == 18: #4PushButton
QAdd(id, PAD4, 1)
QAdd(id, PAD4, 0)
go_short()

elif evt == 19: #5PushButton
QAdd(id, PAD5, 1)
QAdd(id, PAD5, 0)
go_short()

elif evt == 20: #6PushButton
QAdd(id, PAD6, 1)
QAdd(id, PAD6, 0)
go_short()

elif evt == 21: #7PushButton
QAdd(id, PAD7, 1)
QAdd(id, PAD7, 0)
go_short()

elif evt == 22: #8PushButton
QAdd(id, PAD8, 1)
QAdd(id, PAD8, 0)
go_short()

elif evt == 23: #9PushButton
QAdd(id, PAD9, 1)
QAdd(id, PAD9, 0)
go_short()

elif evt == 24: #0PushButton
QAdd(id, PAD0, 1)
QAdd(id, PAD0, 0)
go_short()

elif evt == 25: #-PushButton
QAdd(id, PADMINUS, 1)
QAdd(id, PADMINUS, 0)
go_short()

elif evt == 26: #=PushButton
QAdd(id, PADPLUSKEY, 1)
QAdd(id, PADPLUSKEY, 0)
go_short()

elif evt == 62: #.PushButton
QAdd(id, PADPERIOD, 1)
QAdd(id, PADPERIOD, 0)
go_short()

elif evt == 63: #/PushButton
QAdd(id, PADSLASHKEY, 1)
QAdd(id, PADSLASHKEY, 0)
go_short()

#--------redraw the window--------
Window.RedrawAll()

#--------register the 3 events--------
Register(draw, event, bevent)

Cool idea :slight_smile:

I experimented with your script and modified it a bit to contain all the numpad keys, to approximate numpad key layout a little more, and to preserve indentations so the script can be copied and pasted without any problems.

Some small changes are in there as well, such as adding ESCKEY detection and a clickable Exit button for the script.

Since 1, 3, and 7 keys are back in there, the Top, Front, Right (Side) buttons can optionally come out of the GUI by placing a # character in front of each of those three lines below.

I hope these modifications can be helpful :slight_smile:


import Blender
from Blender import Window, Text, Draw, BGL
from Blender.Window import *
from Blender.Text import *
from Blender.Draw import *
from Blender.BGL import *


#--------do it--------
def go_short():
    QHandle(id)
    Window.RedrawAll()

#--------get 3d window--------
try: # get 3d area
    area = Window.GetScreenInfo(Window.Types.VIEW3D, rect='total')
    id = area[0]['id'] # get the first view id

except: # get text area
    area = Window.GetScreenInfo(Window.Types.TEXT)
    id = area[1]['id'] # get the second text id

#--------create buttons--------
def draw():
    global PushButton15, PushButton16, PushButton17, PushButton18, PushButton19, PushButton20, PushButton21, PushButton22, PushButton24, PushButton25, PushButton26
    glClearColor(0.000, 0.000, 0.000, 0.0)
    glClear(GL_COLOR_BUFFER_BIT)
    
    PushButton('Top', 21, 2, 251, 83, 20, '+SHIFT Bottom View')
    PushButton('Front', 15, 2, 231, 83, 20, '+SHIFT Back View')
    PushButton('Right', 17, 2, 211, 83, 20, '+SHIFT Left View')
    PushButton('/', 63, 2, 191, 42, 20, 'Enter / Leave Local View')
    PushButton('*', 27, 44, 191, 20, 20, 'Rotate View to Object Orientation')
    PushButton('-', 25, 64, 171, 20, 40, 'Zoom Out')
    PushButton('+', 26, 64, 111, 20, 60, 'Zoom In')
    PushButton('7', 21, 2, 171, 20, 20, 'Top View | Click while pressing SHIFT for Bottom View')
    PushButton('8', 22, 23, 171, 20, 20, 'Tilt Up')
    PushButton('9', 23, 44, 171, 20, 20, 'Force Redraw/Recalculation')
    PushButton('4', 18, 2, 151, 20, 20, 'Pan &lt;')
    PushButton('5', 19, 23, 151, 20, 20, 'Toggle Orthogonal / Perspective View')
    PushButton('6', 20, 44, 151, 20, 20, 'Pan &gt;')
    PushButton('1', 15, 2, 131, 20, 20, 'Front View | Click while pressing SHIFT for Back View')
    PushButton('2', 16, 23, 131, 20, 20, 'Tilt Down')
    PushButton('3', 17, 44, 131, 20, 20, 'Side View: Right | Click while pressing SHIFT for Side View: Left')
    PushButton('0', 24, 2, 111, 42, 20, 'View from Active Camera | Hold CTRL to Set Active Camera')
    PushButton('.', 62, 44, 111, 20, 20, 'Center View Around Selection')
    PushButton('EXIT', 10, 2, 91, 83, 20, 'Q or ESC KEY to Exit')

#--------exit function--------
def event(evt, val):
    if (evt== QKEY and not val) or evt == ESCKEY:
        SetKeyQualifiers(0)
        Exit()
    
#--------button events--------
def bevent(evt):
    global letter
    if evt == 69: #DelKey
        QAdd(id, DELKEY, 1)
        QAdd(id, DELKEY, 0)
        go_short()
    

    elif evt == 100: #EXIT
        Exit()

    elif evt == 10: #EscPushButton
        Exit()
    
    elif evt == 15: #1PushButton
        QAdd(id, PAD1, 1)
        QAdd(id, PAD1, 0)
        go_short()

    elif evt == 16: #2PushButton
        QAdd(id, PAD2, 1)
        QAdd(id, PAD2, 0)
        go_short()
        
    elif evt == 17: #3PushButton
        QAdd(id, PAD3, 1)
        QAdd(id, PAD3, 0)
        go_short()
        
    elif evt == 18: #4PushButton
        QAdd(id, PAD4, 1)
        QAdd(id, PAD4, 0)
        go_short()
        
    elif evt == 19: #5PushButton
        QAdd(id, PAD5, 1)
        QAdd(id, PAD5, 0)
        go_short()
        
    elif evt == 20: #6PushButton
        QAdd(id, PAD6, 1)
        QAdd(id, PAD6, 0)
        go_short()
        
    elif evt == 21: #7PushButton
        QAdd(id, PAD7, 1)
        QAdd(id, PAD7, 0)
        go_short()
        
    elif evt == 22: #8PushButton
        QAdd(id, PAD8, 1)
        QAdd(id, PAD8, 0)
        go_short()
        
    elif evt == 23: #9PushButton
        QAdd(id, PAD9, 1)
        QAdd(id, PAD9, 0)
        go_short()
        
    elif evt == 24: #0PushButton
        QAdd(id, PAD0, 1)
        QAdd(id, PAD0, 0)
        go_short()
        
    elif evt == 25: #-PushButton
        QAdd(id, PADMINUS, 1)
        QAdd(id, PADMINUS, 0)
        go_short()
        
    elif evt == 26: #=PushButton
        QAdd(id, PADPLUSKEY, 1)
        QAdd(id, PADPLUSKEY, 0)
        go_short()

    elif evt == 27: #=PushButton
        QAdd(id, PADASTERKEY, 1)
        QAdd(id, PADASTERKEY, 0)
        go_short()
        

    elif evt == 62: #.PushButton
        QAdd(id, PADPERIOD, 1)
        QAdd(id, PADPERIOD, 0)
        go_short()
        
    
    elif evt == 63: #/PushButton
        QAdd(id, PADSLASHKEY, 1)
        QAdd(id, PADSLASHKEY, 0)
        go_short()
    

#--------redraw the window--------
Window.RedrawAll()

#--------register the 3 events--------
Register(draw, event, bevent)


RobertT

Just realised I lost all the indents just pasting the script!! :mad: This means it will throw an error tantrum if you try to run it!

You can get it here instead. Feel free to improve it.

http://homepage.eircom.net/~3d4free/download/LapTopNumPad.py

hope it is useful

Regds
Trevor

Hi RobertT
Geewhizz you are fast. :smiley: Thanks for the additional code. Your modifications expand the virtual numpad to its full glory. I will update the link I just posted with your full key version.

Appreciate the help

Regds
Trevor

Haha, thanks :slight_smile: I was browsing the forum while waiting for several hundred frames to render in Blender, so I had some free time and noticed your cool script. I’m glad the changes worked out.

RobertT

New improved Laptop Numpad Script.

http://homepage.eircom.net/~3d4free/download/Laptop_NumPad.py

right-click on the link and choose Save As.
Copy it to your scripts folder.
It will be available as a System menu item.

regds
Trevor

hi mugwah

I was realy looking forward to trying your script. (as I have frequent misagreements, with my laptop about the interpretation of what I am typing)

but It doesn’t appear in the menu when I refresh.

what version of blender do you use?
I have 241 with full python allso installed

cheers Smitje

Hi Smitje
Sometimes blender does not register the scripts properly in the menu system (on my PC anyway). You can run any script manually this way:

Open a text window and load the script manually with File> Open. Then from the menu, File> Run Python Script, to get it to work.

Hope you find it useful

Regds
T

Thanks that works like a charm :slight_smile:

that makes life a lot easier when working on a laptop.

good job! Cheers
Smitje

When I run the script I get the following error:

I’m using Blender 2.41 w/ Python 2.4 on Windows

Traceback (mose recent call last):
File “C:\Editing\Blender.blender\scripts\Laptop_NumPad.py”, line 46, in ?
id = area[1][‘id’] # get the second text id
IndexError: list index out of range

Hi Snosoe,
The script needs an open 3D viewport to be available. Split your 3D viewport in two and run the script in the right hand window.

This version should be ok
http://homepage.eircom.net/~3d4free/download/Lap_Top_Num_Pad.py

cheers
T

Thanks mugwah,
Works great now, thanks for the help and the great script.

Snosoe

Hi mugwah

Still love your script.:slight_smile:

Yesterday I was using it on the train and I had 2 3d views open, but could controll only one. Do you think it would be possible to switch what window the script controlls?

cheers
Smitje

Thanks very much. still it would be great if there would be a way to redirect blender shortcuts, since this is still about clicking, but really usable for some things(view selected and local view mode). I think that there are still more and more laptopers and the more important shortcuts should be moved to the main keyboard.

Why don’t they instead of emulating the numpad, but remap the numbers.
1 - Top view
2 - Front view
3 - Side view
Shift - 1/2/3 for opposite view

4 - Perspective/Othoganal view
5 - View Selected
6 - Isolated view
7 -
8 -
9 -
0 - camera view

I don’t even use the
rotate keys 2,4,6, & 8.

What are your views on the emulated numpad option?

Hi smitje.
AFAIK scripts can only affect one dominant 3d window as the mouse pointer has to be over the script window to operate it.

Hi CGTiger,
You are quite correct. You lose the direct layer keys but you always have the M KEY!! The script is just another way of doing it.

What CGtiger is refering to is the ‘Emulate Numpad’ button in the System & OpenGL part of the Preferences pulldown. That remaps the 1-0 keys for navigation,

I figured out what the problem is with the script not showing up in the Scripts menu:
There’s an extra newline at the beginning of the file before the #BSP declaration that prevents Blender from finding it.

Simple problem, simple fix.

Thanks raceomazion
Why that script did not show in the scripts menu was was bugging me. Thanks for pointing out the problem! Fixed.

edit

thnx