dotNet Keyboard focus, control keyboard

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  11 November 2013
dotNet Keyboard focus, control keyboard

Hi this is my first post on this forums so I will try to make this post as good as possible

I'm trying to create an dotNet interface overlay in 3ds max with the possibility to do keyboardshortcuts or using a searchfield for example. But what ever I do max wont let go of the keyboard focus, i've tried several different methods like:

form = dotNetObject "form"
form.focus() --only brings form to the front and not the keyboard focus

dnKeyboard = dotNetObject "system.windows.Forms.Control"
keyboard.focus() -- which always returns false


Then there are several methods that actually do work, I will also explain why I don't want to use these:

--this is the best one I've found so far since it does what I want but with activeXcontroler help, which is something I would like to avoid for compatibility issues in the future.
--But this one actually work with out any issus in dotNet right now.
enableAccelerators = false --write this when you want to have control
enableAccelerators = true --and this when your script is done

simple example script:
--dotNet interface
form = dotNetObject "form"
dnKeyboard = dotNetObject "system.windows.Forms.Control"
form.show()

--DotNet function
fn KeyPressed senderArg keyPressEventArgs =
(print (keyPressEventArgs.KeyData))
dotnet.addEventHandler form "KeyUp" KeyPressed

--activeX controller
--Fixing the problem but isn't the nicest solution.
--Run it one more time to giva back controll to max

if (enableAccelerators) then (enableAccelerators = false) else (enableAccelerators = true)







another solution that (kind of)works is to use a regular max rollout, with this solution you for starters get the max rollout which would not work for what I have intended to do, but also a window that constantly must be at the top:

rollout example "example" width:398 height:224
(
timer theTicker interval:15 active:true
dotNetControl dnControl "System.Windows.Forms.Control"
local dnKeyboard = DotNetClass "System.Windows.Forms.Keys"
Local KeyPressed

on theTicker tick do (
dnControl.focus() --sets focus
)

on dnControl KeyDown senderArg keyPressEventArgs do
(
KeyPressed = keyPressEventArgs.keyCode
keyPressEventArgs.SuppressKeyPress = true
print KeyPressed
)

on dnKeys KeyUp senderArg keyPressEventArgs do
(
KeyPressed = undefined
)
)
createDialog example


I hope these solutions can help someone else at least and If anyone has a better solution to my problem please write it below^^
//Christoffer
 
  11 November 2013
you should register to the gotFocus and lostFocus events of your control and enable/disable max accelerators accordingly.
 
  11 November 2013
Originally Posted by lo: you should register to the gotFocus and lostFocus events of your control and enable/disable max accelerators accordingly.


It's very interesting! I would like to see how to do it!
 
  11 November 2013
Originally Posted by try2script: It's very interesting! I would like to see how to do it!

there is tons of samples about this subject on this forum. just search for enableAccelerators
 
  11 November 2013
well in my example in the first post I use the function enableAccelerators, but since It's an old function and based upon Active X I'm not sure that it's a good idea to use it since Microsoft isn't including that package anymore with windows.

But maybe that's the only way right now to control this in Max?

also here is the documentation page for enableAccelerators
http://docs.autodesk.com/3DSMAX/15/...mber=d30e648360
 
  11 November 2013
Yeah this is the method I used as an example in the first post, but since it's part of activeX and Microsoft isn't including that in windows anymore It doesn't seem as the best method to use for this. But maybe there isn't another way right now?
 
  11 November 2013
What does it have to do with ActiveX? It's just a part of the 3dsmax UI message loop.
 
  11 November 2013
Originally Posted by lo: What does it have to do with ActiveX? It's just a part of the 3dsmax UI message loop.


well allot according to the maxscript guide:
http://docs.autodesk.com/3DSMAX/15/...mber=d30e648360
AMAXScript system global called "enableAccelerators" can be set to false whenever an ActiveX control gets focus so that the user can type in the controls.
 
  11 November 2013
That doesn't say accelerators are part of ActiveX.
It says that when you use an activeX control, you should disable accelerators so they don't interfere with keyboard input to ActiveX controls ... or for that matter, any non-max controls, such as dotnet controls.
 
  11 November 2013
ah.. that's true^^

well in that case the problem was solved from the beginning, I just din't realize it...
Thanks for the clarification!
 
  11 November 2013
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:54 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.