win32api.SetCursorPos() question

Gary Richardson garyr at fidalgo.net
Sun Sep 19 13:56:23 EDT 2004


"Heiko Wundram" <heikowu at ceosg.de> wrote in message
news:mailman.3505.1095596265.5135.python-list at python.org...
> Am Samstag, 18. September 2004 22:41 schrieb Gary Richardson:
> > I tried that. It doesn't produce an error but no cursor appears.
>
> I don't know much about the win32-api, but SetCursorPos sounds like a
> text-console command, not like something that has to do with windows.
> Funtions that operate on a window take a HWND (window handle), but this
> function doesn't, so this certainly sounds like text-console.
>
> Now, why are you trying to position the cursor in a Tk Window anyway? The
> Tk-Window is no text console, it's just a plain window on the screen, and
you
> can draw in the window using the normal Tk drawing primitives.
>
> Maybe, if you post some more info on what you're trying to do, can we help
you
> better...
>
> Heiko.

Heiko,

Thank you for your reply. It encouraged me to read the MSVS documentation on
cursors a little more closely and to try a few things. I found that the
win32api function GetCursorPos() returns the position of the cursor with
respect to the computer screen so assuming that SetCursorPos() uses the same
coordinate system, I would have to add to my window coordinates the position
of the canvas with respect to the screen. I then took another look at
Vincent Wehren's and DogWalker's (direct email) suggestion that I pass
SetCursorPos() a tuple instead of a pair of values and found that did indeed
work. The cursor was there, it just wasn't where I expected it to be.

I'm using a Tk Canvas window to display various objects, one of which can be
a block of text entered from the keyboard. The user positions the cursor to
the desired position and begins typing, terminating the entry by pressing
the Esc key. From that point the text block can be manipulated (moved,
copied or deleted) by means of the mouse. As it is now, during text entry,
there is no indication of where the next character is to be entered. So I
thought it would be nice if I could indicate the insertion point as is usual
with text entry programs, editors, etc.

Thanks for all the help.

Gary








More information about the Python-list mailing list