[HowTo] immediate "sendkeys" with Ruby ? (SketchUp)

M

Marcio Braga

I need to send a key (letter "x" for example) to SketchUp (shortcut) in
the middle of a code execution. I'm trying to use the command:

WIN32OLE.new("WScript.Shell").SendKeys("x")

But this way, the "x" is not being sent immediately. For example:

p "test1"
WIN32OLE.new("WScript.Shell").SendKeys("x")
p "test2"

I see "test1" and "test2" arriving (on SketchUp console) but I do not
see SketchUp responding to shortcut "x" during execution of the code.
"x" arrives only when the code finishes and return control to SketchUp.

Is any way to send this "x" ... immediately ?

Thank you
Marcio
 
D

Dejan Dimic

I need to send a key (letter "x" for example) to SketchUp (shortcut) in
the middle of a code execution. I'm trying to use the command:

WIN32OLE.new("WScript.Shell").SendKeys("x")

But this way, the "x" is not being sent immediately. For example:

p "test1"
WIN32OLE.new("WScript.Shell").SendKeys("x")
p "test2"

I see "test1" and "test2" arriving (on SketchUp console) but I do not
see SketchUp responding to shortcut "x" during execution of the code.
"x" arrives only when the code finishes and return control to SketchUp.

Is any way to send this "x" ... immediately ?

Thank you
Marcio

Before sending any keys you should verify to whom you are sending
them.

Take look at: http://rubyonwindows.blogspot.com/2007/05/automating-applications-with-ruby.html

Regards,
Dima
 
M

Marcio Braga

Dejan said:
Before sending any keys you should verify to whom you are sending
them.

Return of AppActivate is true so I think I'm sending to the right place
(I can see SketchUp window going to focus), but the shortcut "Y" is not
triggered before the end of code execution.

s=WIN32OLE.new("WScript.Shell")
p s.AppActivate("SketchUp") # return is true ...
sleep(5)
p s.SendKeys("y") # should trigger Y shortcut
sleep(5)
# no signs of the shortcut ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top