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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fefb3f3bb1fea41dd2de9dc299f1ded6?d=identicon&s=25 Marcio Braga (marcioab)
on 2008-12-22 01:26
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
04952a6ee948f345e9c3727850d09a1b?d=identicon&s=25 Dejan Dimic (Guest)
on 2008-12-22 23:10
(Received via mailing list)
On Dec 22, 1:18 am, Marcio Braga <mbraga0...@gmail.com> wrote:
>
> 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
> --
> Posted viahttp://www.ruby-forum.com/.

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

Take look at:
http://rubyonwindows.blogspot.com/2007/05/automati...

Regards,
Dima
Fefb3f3bb1fea41dd2de9dc299f1ded6?d=identicon&s=25 Marcio Braga (marcioab)
on 2008-12-23 02:08
Dejan Dimic wrote:
> 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 ...
This topic is locked and can not be replied to.