Pressing keys in the listener

Hi,
I am novice to the site and to maxscript.
I am using the pickobject() fn in a dotnet checkbox eventhandler function.
The problem is it works fine, if you select the picked object and not cancel the action.
If i know how to press the "escape" key in the listener i will be able to stop the function. I tried to use the "sendkeys" class with the "sendwait" method, but it only works as input in the listener.
Is there a way to press a key in a dialog (maxscript listener) by its HWND from a script.
Thanks
Tsvetan

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ewok's picture

Hi guys, I just tried the

Hi guys,

I just tried the code by anubis in order to print an "E" in the MAXScriptListener by sending the "{E}" key to it.

But, it doens't work. I only get this result:

true
MCR_SendKeys()
undefined

Just in case the modified code looks like that:

actionMan.executeAction 0 "40472" -- Open the Listener
 
fn MCR_SendKeys sysKey = 
(
	local WM_ACTIVATE = 0x6
	local SendKeys = dotNetClass "System.Windows.Forms.SendKeys"
	ListenerHWND = (windows.getChildHWND 0 "MAXScript Listener")[1]
	MacroChHWND = (windows.getChildrenHWND ListenerHWND)[2][1]
 
	Windows.sendMessage MacroChHWND WM_ACTIVATE MacroChHWND 0
	SendKeys.SendWait sysKey
)
 
MCR_SendKeys "{E}" -- send Escape key to MacroRecorder sub-window

Does anyone konw what's wrong?

I also don't understand what local WM_ACTIVATE = 0x6 stands for.

TsveTan's picture

.

Yes of course, it was helpful. I searched 2-3 days on the web for a way.
I believe we will meet again.
Thank you (Blagodarq)

Ewok's picture

*

*
Moved post to the right place.

Anubis's picture

welcome ;)

I think I forgot to say Welcome to the site and scripting, so I do it right now :)

Glad to know as well that I was helpful with something.

Anubis

my recent MAXScripts RSS (archive here)

TsveTan's picture

Many Thanks, colleagues I

Many Thanks, colleagues
I write down the function body in my case to be much clear, if someone is searching on the web for a similar solution.
The "MCR_SendKeys" function is exactly what I am looking for.

actionMan.executeAction 0 "40472" -- Open the Listener
global SendKeys = dotNetClass "System.Windows.Forms.SendKeys"
fn MCR_SendKeys sysKey = 
 (
  local WM_ACTIVATE = 0x6
  ListenerHWND = (windows.getChildHWND 0 "MAXScript Listener")[1]
  MacroChHWND = (windows.getChildrenHWND ListenerHWND)[1][1]
  Windows.sendMessage MacroChHWND WM_ACTIVATE MacroChHWND 0
  SendKeys.SendWait sysKey
 )
 
fn checkedbtn o a =
 (
  if o.checked == true then
   (
    o.backcolor = o.backcolor.gold
    obj = pickobject filter:shapeFilt forceListenerFocus:false
    if obj != #escape and obj != undefined then
     (
      o.text = obj.name
      o.checked = false
     )
   )
  else
   (
    MCR_SendKeys "{Escape}" -- send Escape key to the Listener sub-window
    o.backcolor = o.backcolor.azure
   )
 )
dotnet.addEventHandler checkBox0 "checkedChanged" checkedbtn
Anubis's picture

pickObject prompt:"..." ?

Maybe you use the optional #prompt argument with pickObject(), which popup the Listener?
Its not very likeable option to me.

Here is a function anyway (right copy from my archive) for sending keys to the MacroRecorder sub-window (the pink area in the Listener dialog), but you can modify it to send keys to the main (white area) sub-window. If so, change the [2][1] in line "MacroChHWND = ..." to [1][1] (first sub-window).

actionMan.executeAction 0 "40472" -- Open the Listener
 
fn MCR_SendKeys sysKey = 
(
	local WM_ACTIVATE = 0x6
	local SendKeys = dotNetClass "System.Windows.Forms.SendKeys"
	ListenerHWND = (windows.getChildHWND 0 "MAXScript Listener")[1]
	MacroChHWND = (windows.getChildrenHWND ListenerHWND)[2][1]
 
	Windows.sendMessage MacroChHWND WM_ACTIVATE MacroChHWND 0
	SendKeys.SendWait sysKey
)
 
MCR_SendKeys "{ESC}" -- send Escape key to MacroRecorder sub-window

I hope this helps

my recent MAXScripts RSS (archive here)

jos's picture

you can check if the obj is

you can check if the obj is undefined.
pickobject will return undefined when the action is cancelled.
Can't help you with the keys..

obj = pickobject()
if obj != undefined then
(
   ...
)
else
(
  --uncheck checkbox
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.