# Mouse click with win32api

**URL:** <https://www.ruby-forum.com/t/mouse-click-with-win32api/88794>\
**Category:** Ruby\
**Created:** [March 14, 2007, 1:46pm UTC](https://www.ruby-forum.com/t/mouse-click-with-win32api/88794 "2007-03-14T13:46:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emilsverige](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/77aa72/32.png) [@emilsverige](https://www.ruby-forum.com/u/emilsverige)\
**Post date:** [March 14, 2007, 1:46pm UTC](https://www.ruby-forum.com/t/mouse-click-with-win32api/88794/1 "2007-03-14T13:46:14Z")

</div>

Hi,  
I would like to write a script like this:

mouse.move\_cursor\_to( x, y )  
mouse.click\_left\_button()

I have read that I can use AutoIt, but that the program has to have an  
ole interface for it to be possible. That autoit doesn’t really move the  
mouse cursor, but rather tells the program to click a certain  
coordinate.

Is it possible to do this using win32api instead of autoIt, or is there  
another neat way of acheive it?

Regards  
Emil

---

<div class="post-metadata">

**Author:** ![emilsverige](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/77aa72/32.png) [@emilsverige](https://www.ruby-forum.com/u/emilsverige)\
**Post date:** [March 14, 2007, 1:55pm UTC](https://www.ruby-forum.com/t/mouse-click-with-win32api/88794/2 "2007-03-14T13:55:31Z")

</div>

Emil S. wrote:

> Hi,  
> I would like to write a script like this:
> 
> mouse.move\_cursor\_to( x, y )  
> mouse.click\_left\_button()
> 
> I have read that I can use AutoIt, but that the program has to have an  
> ole interface for it to be possible. That autoit doesn’t really move the  
> mouse cursor, but rather tells the program to click a certain  
> coordinate.
> 
> Is it possible to do this using win32api instead of autoIt, or is there  
> another neat way of acheive it?
> 
> Regards  
> Emil

Sorry, I was to fast to create a post.  
AutoIt seems to do the trick for me:

gem install watir  
regsvr32 C:\ruby\lib\ruby\gems\1.8\gems\watir-1.4.1\watir\AutoItX3.dll  
irb  
require ‘rubygems’  
require ‘win32ole’  
a = WIN32OLE.new(“AutoItX3.Control”)  
a.mousemove(100, 100)  
a.mouseclick

---

<div class="post-metadata">

**Author:** ![emilsverige](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/77aa72/32.png) [@emilsverige](https://www.ruby-forum.com/u/emilsverige)\
**Post date:** [March 14, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/mouse-click-with-win32api/88794/3 "2007-03-14T14:01:49Z")

</div>

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf  
Of  
Emil S.  
Sent: Wednesday, March 14, 2007 2:46 PM

> coordinate.
> 
> Is it possible to do this using win32api instead of autoIt, or is there  
> another neat way of acheive it?

There is simple cpp code attached (as well as extconf for it).  
It is compiled into extension, having module Rwin32::Emulate with  
methods  
mouse\_down!, mouse\_up!, key\_down!, key\_up!

It can be used as is, or as a learning material of “how to do this”. Any  
questions are welcome. If somebody wants to do something more  
full-featured  
on this basis, he is welcome too.

V.
