PDA

View Full Version : Keyboard Callback


U.S.S. Speed
01-01-2008, 08:36 PM
Not often that I ask for help about MaxScript... Normaly the help solve all my problems, but not this time it seams.

Is it possible to call a function when the state of a keyboard key change?
I'm aware MaxScript is limited to Alt, Ctrl, Shift and Esc.

But even then, I can't seam to find any callback for the state of those key.

To explain a bit more my problem, I want to create a button that change depending of the situation. Currently, the button change is bound to a viewport refresh callback. (registerRedrawViewsCallback) It's great because everytime the user click or press a normal keyboard key, the viewport is redrawn.

However, this callback isn't called when the user press Shift, Alt, or Ctrl.

Anyway to do this? Is it possible to make the check at X millisec?
Or is there a better callback to use?

(I was a bit surprise that there is no keyboard callback)

Bobo
01-01-2008, 08:54 PM
Keyboard shortcuts are handled completely independently from MAXScript - all you can do is assign a MacroScript to those keys you want to monitor via the Customize UI dialog. But this is of course a bad idea, as there are already not enough keyboard shortcut combinations left for general use.

You CAN check for Alt, Shift and Ctrl by polling every N milliseconds - either by using a timer UI control or the timer DotNet control as described on my site (DotNet page) or in the 2008 edition of the Help (I am pretty sure I included it there). 5 to 10 checks per second shouldn't cause noticeable performance issues.

U.S.S. Speed
01-02-2008, 01:12 AM
At first I was thinking shortcut, but after reading a bit I understood it was a bad idea. (Limit of shortcut, but also how maxscript doesn't handle them)

The idea was to modify the behaviour of a button depending of the state of the modifier key (the only one you can check with MaxScript)... I didn't really want to do a polling every x milliseconds as I never actually did something like that... Guess I will have to learn a new thing today. :D

So, which one should I use, which is the fastest? Timer or the DotNet solution?

BTW, thanks a lot for the help.

Bobo
01-02-2008, 08:12 AM
At first I was thinking shortcut, but after reading a bit I understood it was a bad idea. (Limit of shortcut, but also how maxscript doesn't handle them)

The idea was to modify the behaviour of a button depending of the state of the modifier key (the only one you can check with MaxScript)... I didn't really want to do a polling every x milliseconds as I never actually did something like that... Guess I will have to learn a new thing today. :D

So, which one should I use, which is the fastest? Timer or the DotNet solution?

BTW, thanks a lot for the help.

Inside your code, you can check for the modifier key state without a polled test. If something else (redraw callback, some other callback) is calling your function, just add a test for Keyboard.ShiftPressed, Keyboard.AltPressed etc. inside the function and change the behaviour of your code.

If you DO have to go with a polling method and you are running Max 9 or higher, the DotNet solution is better as it does not require a rollout to function.

U.S.S. Speed
01-02-2008, 04:34 PM
The idea was actually the lack of refresh of my button icon when no mouse action was involve. The redraw isn't called when modifier keys are pressed... So polling is the way to go I guess.

Thanks, I will check the DotNet one.

Bobo
01-02-2008, 07:20 PM
The idea was actually the lack of refresh of my button icon when no mouse action was involve. The redraw isn't called when modifier keys are pressed... So polling is the way to go I guess.

Thanks, I will check the DotNet one.

Is the button icon on a toolbar on in the dialog/floater's rollout?

U.S.S. Speed
01-02-2008, 08:06 PM
Is the button icon on a toolbar on in the dialog/floater's rollout?

On a floater. Does that change something?

CGTalk Moderation
01-02-2008, 08:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.