Notifications
Clear all

[Closed] catching mouseclicks

Hi,

I’m working on a script to make screengrabs of anything in 3dsMax: viewports, dialogs, scripts. Just still images. I’m using this code by DenisT to catch mouseclicks anywhere on the screen. This works pretty good but there’s a problem. When I press the ESC key a few times I get an error and have to quit 3dsMax to get out of it.
Is there a way to block the esc key while this script is running? I’ve tried to catch the esc-key but this works only sometimes, while other times the same error pops up.

Klaas

13 Replies

i can reproduce the crash with only my code run… probably something else causes that

what does this error say?

the only way is to use Keyboard Hook (WH_KEYBOARD_LL) … with Mouse Hook will be much easier and cleaner to catch mouse clicks.

but i don’t want to show on this forum how to write a hook. because i cannot be sure that all people will use it intelligently

Hi Denis,

this is the error, nothing is printed to the listener however.

I’ve got it in max 2012 and 2013. Try to tap the esc key as fast as you can 5 to 10 times. That triggers the error for me each time.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

it doesn’t crash for me…
if you do some operations in mouseTimerTick function set timer.enabled to OFF before the an operation, and to ON after. it might help.

The issue seems to be in the timer, like you suggest. I’ve replaced this timer with another timerwhich seems to resolve the problem. If I press the ESC key a few times quickly the timer stops, but doesn’t give me an error. For me this is OK, but it’s still odd. Maybe other people can confirm this as well.

try(mouse_timer.Dispose()) catch()
 
 mouse_timer = dotnetobject "System.Timers.Timer"
 mouse_timer.interval = 100
 fn mouseTimerTick s e =
 (
 	format "pos %
" mouse.screenPos
 )
 dotnet.addEventHandler mouse_timer "Elapsed" mouseTimerTick
 mouse_timer.Start()

i’ve played with System.Windows.Forms.Timer. now i’m in max 2012, and seams like the timer works differently than it worked in max 2010. it looks like it takes a focus on every tick, and returns after the event callback. but if the focus was changed during the event callback, it doesn’t return it right. definitely i don’t remember this behavior on previous versions… and i need to double-check it. but the fact is – some of my scripts which worked well in max 2010 stopped working correctly in max 2012

Two things that might sound stupid:

escapeEnabled ? Also dont forget to dotNet.setLifetimeControl on your .net timer

Well, it’s my first time using such a timer, so nothing sounds stupid to me. Could you show in my example how to do it?

Page 1 / 2