# Automate a button click

**URL:** <https://www.ruby-forum.com/t/automate-a-button-click/166322>\
**Category:** Ruby-Gnome 2\
**Created:** [April 23, 2009, 9:18pm UTC](https://www.ruby-forum.com/t/automate-a-button-click/166322 "2009-04-23T21:18:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [April 23, 2009, 9:18pm UTC](https://www.ruby-forum.com/t/automate-a-button-click/166322/1 "2009-04-23T21:18:27Z")

</div>

Anyone know what’s the matter with this code to automate a button click?

def make\_event\_button(window, x, y, button, type)  
case type  
when :press  
event\_button = Gdk::EventButton.new(Gdk::Event::BUTTON\_PRESS)  
when :release  
event\_button = Gdk::EventButton.new(Gdk::Event::BUTTON\_RELEASE)  
end  
event\_button.x = x  
event\_button.y = y  
event\_button.button = button  
event\_button.time = Gdk::Event::CURRENT\_TIME  
event\_button.window = window  
event\_button  
end

def left\_click\_on(widget)  
make\_event\_button(widget.window, 0, 0, 1, :press).put  
make\_event\_button(widget.window, 0, 0, 1, :release).put  
end

left\_click\_on(gtk\_button)

# –end

thanks  
Dan

* * *

Daniel Benjamin Lucraft

[www.daniellucraft.com/blog](http://www.daniellucraft.com/blog)  
[twitter.com/danlucraft](http://twitter.com/danlucraft)

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [April 24, 2009, 12:05am UTC](https://www.ruby-forum.com/t/automate-a-button-click/166322/2 "2009-04-24T00:05:08Z")

</div>

am Thu, 23 Apr 2009 20:17:04 +0100, tat Daniel L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) der Welt kund:

> Anyone know what’s the matter with this code to automate a button click?

Hi,

I don’t know, whats wrong with your code, but if you only want to  
simulate a button click, why not simply use Gtk::button.activate?

## Cheers, detlef

[http://det.cable.nu](http://det.cable.nu)

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [April 24, 2009, 10:05am UTC](https://www.ruby-forum.com/t/automate-a-button-click/166322/3 "2009-04-24T10:05:24Z")

</div>

Yes, thanks for the tip. I’d prefer to create click events because I  
am trying to simluate user input as closely as possible for my  
features. Code that simulates a click can be used everywhere, not just  
on a button widget.

I tried the activate option anyway (I’ll try anything at this point)  
but ran into problems. It works on standard buttons, but for some  
reason when I call ‘activate’ on a button in a (non-modal)  
FileChooserDialog, the dialog will hang with the button depressed.

I’ve not been able to figure out why this is. The stranger part is  
that it doesn’t just hang my application, but in fact hangs the event  
loops for ALL applications I have open. I can just about tell Ubuntu  
to forcibly close my app, which brings everything else back to life,  
thankfully. But my app is dead to the world.

What strange spirits have I angered, please?

Dan

* * *

Daniel Benjamin Lucraft

[www.daniellucraft.com/blog](http://www.daniellucraft.com/blog)  
[twitter.com/danlucraft](http://twitter.com/danlucraft)

2009/4/23 Detlef R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [April 24, 2009, 11:26am UTC](https://www.ruby-forum.com/t/automate-a-button-click/166322/4 "2009-04-24T11:26:45Z")

</div>

Cant you use this:

.signal\_emit(:clicked)

To trigger a signal?
