[wxpython-users] any tips on doing an on-screen keyboard?
Stef Mientki
s.mientki at ru.nl
Thu May 1 02:33:26 PDT 2008
I don't know if you already solved the problem,
but for a win-mobile emulator I needed something similar,
so here is the solution I used.
I made capture of the keyboard from the M$ Device Emulator and put it in
a png-file.
I catch the left key down event on the image,
calculate the position of the click in the image,
and send the result to windows with sendkeys.
Works like a charm (but probably only under windows.
Code is below (not all special keys are in there yet).
cheers,
Stef
def _On_KB ( self, event ) :
x,y = event.GetPosition ()
if ( x < 19 ) and ( y < 19 ) :
self.kb1.Show ( not ( self.kb1.IsShown () ) )
self.kb2.Show ( not ( self.kb2.IsShown () ) )
else :
import SendKeys
x0 = ( 19, 25, 30, 34, 22 )
kar = ( ( '\x001234567890-=\0xx\0xx' ),
( '\tqwertyuiop[]]' ),
( '\x00asdfghjkl;\'\r\r' ),
( '\x00zxcvbnm,./\r\r\r' ),
( '\x00@`\\ \x00\x00\x00\x00\x00'))
# determine the row and col index
x, y = event.GetPosition ()
row = y / 16
xfirst = x0 [ row ]
# top row has a little bit smaller keys
if row == 0 :
col = 1 + ( x - xfirst ) / 17
else :
col = 1 + ( x - xfirst ) / 18
col = max ( 0, col )
key = kar[row][col]
#print event.GetPosition () ,row,col,str(ord(key))
# if key = 0, we need to determine a special key
if ord ( key ) == 0 :
if row == 4 :
if col == 11 : key = '{LEFT}'
# now send the key to windows
SendKeys.SendKeys ( key ,
with_spaces = True,
with_tabs = True )
More information about the wxpython-users
mailing list