Re: Rick Towler please come in again!I can't send a email to you?! [message #55693] |
Wed, 05 September 2007 09:44 |
Rick Towler
Messages: 821 Registered: August 1998
|
Senior Member |
|
|
airy.jiang wrote:
> First,normally, I can use the directinput.dlm access the keyboard and
> mouse,but sometimes ,when I set timer of the Widget_Base(maybe the top
> base) ,it doesn't works.I don't know why.I've read the doc,and tried
> the way that set the keyword "Exclusive" equal 1 of the function
> "DI_AquiredKeyboard",but I failed to control the function to get the
> mouse or keyboard from the right widget.Why?
I'm not sure I fully understand your question. Do you have multiple
windows where you are acquiring input? When you say you can't get
keyboard input from the right widget, do you ever get it from the right
widget? If not, and you do have multiple windows, the issue may be that
the directInput.dlm isn't getting the correct handle to the "right" widget.
Officially, IDL doesn't give you access to the underlying OS's reference
to a window object. directInput needs this reference, and at the time
the best workaround was to get the active window handle which is why I
stress in the docs that you must acquire the devices immediately after
you realize your widget hierarchy.
The latest version of directInput.dlm (the one you have downloaded) has
an undocumented keyword that takes advantage of an undocumented function
in IDL. You can get the underlying OS window handle of a widget element
thusly:
DEVICE, widget_id=tlb, GET_WIDGET_HANDLE=hWin
and you can pass that to the di_acquire* functions:
diID = di_InitInterface()
diKeyboardID = di_acquireKeyboard(diID, WINHANDLE=hWin)
This will ensure that the di objects are associated with the windows you
want them to be associated with. As always, use at your own risk, the
interface may change or ITT may remove the feature.
> Second,Is that nessesary to set the timer at the begining and after
> the event processing?Why should it refresh every 0.2 second to get get
> the infomation of the mouse or keyboard?Can't I use the function
> "DI_PollMouse" to get the mouse or keyboard whenever?
At the beginning of what? If you mean setting it at the end of the main
function and after the timer event processing then no, it isn't. But
you need to start the timer at some point and that seems as good a point
as any.
There are lots of reasons to poll much faster than even 5 Hz. The
slower you poll and the slower you re-draw the more "rough" the
interface will become. The directInput dlm is not buffering any of the
input so "what you poll is what you get" so you may lose keystrokes. I
use this structure mainly because I am generating animations and much is
going on even if the user isn't interacting with the keyboard and mouse.
Lastly, if you structure your event properly, there is very little
overhead in processing the event so there really isn't a penalty.
-Rick
|
|
|