Cursor movement question

J

Jive Dadson

Howdy, folks. I am using wxPython 2.8 on Windoze XP Pro. I want my
application to move the cursor and the mouse-point (the coordinates in
the mouse-click events) to the left when the user presses the left-arrow
key, up when they press the up-arrow key, etc.. I think I can figure
out how to grab the arrow key events, but I can't find how to move the
cursor. I tried calling wx.SetCursorEvent(x,y), but no joy.

Can you help?

Thankee,
Jive
 
J

Jive Dadson

Aahz said:
Perhaps you could post the solution for posterity's sake?

The double secret magic encantation is "WarpPointer." Unfortunately, it
does not work in a plain vanilla ScrolledWindow. ScrolledWindow captures
the event and scrolls by the default scroll amount of 20 pixels. I think
I can figure out a work-around, but I have not yet done so.

self.bmp.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

def OnKeyDown(self, event):
# Use direction keys to move cursor one pixel

x,y = event.GetPosition()
keycode = event.GetKeyCode()
X = 0
Y = 0
if keycode == wx.WXK_LEFT:
X = -1
elif keycode == wx.WXK_RIGHT:
X = 1
elif keycode == wx.WXK_UP:
Y = -1
elif keycode == wx.WXK_DOWN:
Y = 1
else:
return

x = max(0,min(self.size[0]-1,x+X))
y = max(0,min(self.size[1]-1,y+Y))
self.bmp.WarpPointer(x, y)
self.bmp.SetFocus()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top