# Keyboard access

**URL:** <https://www.ruby-forum.com/t/keyboard-access/56658>\
**Category:** Ruby\
**Created:** [April 2, 2006, 10:41am UTC](https://www.ruby-forum.com/t/keyboard-access/56658 "2006-04-02T10:41:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [April 2, 2006, 10:41am UTC](https://www.ruby-forum.com/t/keyboard-access/56658/1 "2006-04-02T10:41:30Z")

</div>

How can I gain access to the keyboard so that I can feed output from  
my ruby program into an application that only accepts input via the  
keyboard?

I want the application to think the input is coming from the keyboard  
when it is really coming from a ruby program output.

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [April 2, 2006, 10:53am UTC](https://www.ruby-forum.com/t/keyboard-access/56658/2 "2006-04-02T10:53:47Z")

</div>

I am using Windows2000.

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [April 2, 2006, 5:03pm UTC](https://www.ruby-forum.com/t/keyboard-access/56658/3 "2006-04-02T17:03:46Z")

</div>

DÅ?a NedeÄ¾a 02 AprÃ­l 2006 10:39 Harry napÃ­sal:

> How can I gain access to the keyboard so that I can feed output from  
> my ruby program into an application that only accepts input via the  
> keyboard?
> 
> I want the application to think the input is coming from the keyboard  
> when it is really coming from a ruby program output.
> 
> Thanks for any help.

Is it a console or window application?

In the former case, a simple pipe should suffice, in the latter, you’re  
probably looking at using OLE to run the application from within Ruby  
and  
fake keypresses using the Windows Scripting Host facilities.

David V.  
Probably Wrong

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [April 2, 2006, 5:35pm UTC](https://www.ruby-forum.com/t/keyboard-access/56658/4 "2006-04-02T17:35:15Z")

</div>

Harry wrote:

> I am using Windows2000.

Go grab AutoItX, and script it from Ruby.

require ‘win32ole’  
app\_window\_title = “The App I Want To Type Into”  
@au3 = WIN32OLE.new(“AutoItX3.Control”)  
@au3.opt(“WinTextMatchMode”, 2)  
@au3.Run( “C:\Program Files\SomeApp.exe” )  
@au3.WinWaitActive( app\_window\_title )  
@au3.Send( “Some text to type to the application” )

–  
James B.

[http://web2.0validator.com](http://web2.0validator.com) - We’re the Dot in Web 2.0  
[http://refreshingcities.org](http://refreshingcities.org) - Design, technology, usability  
[http://yourelevatorpitch.com](http://yourelevatorpitch.com) - Finding Business Focus  
[http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [April 3, 2006, 11:56am UTC](https://www.ruby-forum.com/t/keyboard-access/56658/5 "2006-04-03T11:56:32Z")

</div>

I neglected to say that it is a windows application.  
OLE was the answer.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [April 3, 2006, 11:59am UTC](https://www.ruby-forum.com/t/keyboard-access/56658/6 "2006-04-03T11:59:43Z")

</div>

That was exactly what I was looking for.  
I tried it out Monday morning and it worked.  
Excellent!!

Thank you.
