[Closed] 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
you should register to the gotFocus and lostFocus events of your control and enable/disable max accelerators accordingly.
there is tons of samples about this subject on this forum. just search for enableAccelerators
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/ENU/MAXScript-Help/index.html?url=files/GUID-F9BDCDFD-5C2D-42ED-A840-184795A2E057.htm,topicNumber=d30e648360
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?
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/ENU/MAXScript-Help/index.html?url=files/GUID-F9BDCDFD-5C2D-42ED-A840-184795A2E057.htm,topicNumber=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.
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.
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!