# Mouse block and key pressed simulation?

**URL:** <https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511>\
**Category:** Ruby\
**Created:** [July 4, 2007, 9:29am UTC](https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511 "2007-07-04T09:29:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mihai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@mihai](https://www.ruby-forum.com/u/mihai)\
**Post date:** [July 4, 2007, 9:29am UTC](https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511/1 "2007-07-04T09:29:05Z")

</div>

How can i block and release the mouse and keyboard and how can a  
simulate a key pressed in ruby? (for exemple i want to press enter key)

---

<div class="post-metadata">

**Author:** ![mihai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@mihai](https://www.ruby-forum.com/u/mihai)\
**Post date:** [July 4, 2007, 5:06pm UTC](https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511/2 "2007-07-04T17:06:24Z")

</div>

On Jul 4, 2007, at 2:29 AM, mihai wrote:

> How can i block and release the mouse and keyboard and how can a  
> simulate a key pressed in ruby? (for exemple i want to press enter  
> key)
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Depends …

---

<div class="post-metadata">

**Author:** ![mihai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@mihai](https://www.ruby-forum.com/u/mihai)\
**Post date:** [July 5, 2007, 8:39am UTC](https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511/3 "2007-07-05T08:39:28Z")

</div>

John J. wrote:

> On Jul 4, 2007, at 2:29 AM, mihai wrote:
> 
> > How can i block and release the mouse and keyboard and how can a  
> > simulate a key pressed in ruby? (for exemple i want to press enter  
> > key)
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> Depends …

depends of what?  
i have a window with OK and CANCEL button wich appears. and i want when  
that window is active to block the mouse and the keyboard and send the  
key enter to press the OK button

---

<div class="post-metadata">

**Author:** ![mihai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@mihai](https://www.ruby-forum.com/u/mihai)\
**Post date:** [July 5, 2007, 11:28am UTC](https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511/4 "2007-07-05T11:28:53Z")

</div>

Bulhac M. wrote:

> > Depends …
> 
> depends of what?  
> i have a window with OK and CANCEL button wich appears. and i want when  
> that window is active to block the mouse and the keyboard and send the  
> key enter to press the OK button

Ok, so now we know it’s not a web app. Which platform are you  
developing on? What toolkit? Or are you driving a second app from your  
ruby script? Can you show us some code?

---

<div class="post-metadata">

**Author:** ![mihai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@mihai](https://www.ruby-forum.com/u/mihai)\
**Post date:** [July 5, 2007, 1:02pm UTC](https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511/5 "2007-07-05T13:02:15Z")

</div>

mihai wrote:

> How can i block and release the mouse and keyboard and how can a  
> simulate a key pressed in ruby? (for exemple i want to press enter key)

Hi Mihai,

This may be a GUI toolkit specific issue.  
So, you need to look for the hint into the gui toolkit(eg. GTK, QT, Tk)  
specifications.

All the best,

Alin

---

<div class="post-metadata">

**Author:** ![mihai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@mihai](https://www.ruby-forum.com/u/mihai)\
**Post date:** [July 5, 2007, 3:07pm UTC](https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511/6 "2007-07-05T15:07:17Z")

</div>

> i have a window with OK and CANCEL button wich appears. and i want when  
> that window is active to block the mouse and the keyboard and send the  
> key enter to press the OK button

This to me sounds like you’re trying to achieve keyboard and mouse  
emulation. Is this correct?

---

<div class="post-metadata">

**Author:** ![mihai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/35a633/32.png) [@mihai](https://www.ruby-forum.com/u/mihai)\
**Post date:** [July 5, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/mouse-block-and-key-pressed-simulation/108511/7 "2007-07-05T16:46:32Z")

</div>

On Jul 5, 2007, at 8:06 AM, Dan Stevens (IAmAI) wrote:

> > John J. wrote:
> > 
> > > Depends …

That’s what I mean by depends… it depends greatly on the  
environment you want it to work in. Unfortunately this sort of thing  
can be very implementation specific. Unix shell? Dos box? Windows? OS  
X ? KDE?  
All have their own ways of doing this stuff.
