# Gtkmozembed ctrl-A

**URL:** <https://www.ruby-forum.com/t/gtkmozembed-ctrl-a/90468>\
**Category:** Ruby-Gnome 2\
**Created:** [March 29, 2007, 12:58am UTC](https://www.ruby-forum.com/t/gtkmozembed-ctrl-a/90468 "2007-03-29T00:58:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [March 29, 2007, 12:58am UTC](https://www.ruby-forum.com/t/gtkmozembed-ctrl-a/90468/1 "2007-03-29T00:58:48Z")

</div>

I have an application that has gtkmozembed in it. When I press  
control-A, the entire page is selected. Great. I would like for that  
same action to take place when the user presses a “select all” button.

There should be something to emit a keystroke programmatically. Can  
someone point me in the right direction?

Thanks,  
Alan

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [March 29, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/gtkmozembed-ctrl-a/90468/2 "2007-03-29T20:22:01Z")

</div>

Hi,

On Thu, Mar 29, 2007 at 01:57:42AM +0300, Alan L. wrote:

> There should be something to emit a keystroke programmatically. Can  
> someone point me in the right direction?

I don’t know if gtkmozembed has a method for that, but here’s a little  
code  
snippet to synthesize key events:

module Gtk  
class Widget  
def send\_key(name)  
keyval = Gdk::Keyval.from\_name(name)  
unless keyval.zero?  
event = Gdk::EventKey.new(Gdk::Event::KEY\_PRESS)  
event.window = window  
event.hardware\_keycode =  
Gdk::Keymap.default.get\_entries\_for\_keyval(keyval)[0][0]  
event.keyval = keyval  
event.time = Gtk.current\_event\_time  
Gtk.idle\_add do  
self.event(event)  
false  
end  
return true  
else  
return false  
end  
end  
end  
end

With this loaded you can call send\_key on any Gtk::Widget, and pass in  
a keyname as the first parameter (e.g. ‘a’). You need to extend this a  
bit to  
also allow Ctrl, I think it involves setting a mask on event.state.

I’m not sure if this method is sane, but it works fine here. I think  
it didn’t work quite right without the Gtk.idle\_add call, but you should  
first try without it and see if it does in your app.

Also, it’s possible this doesn’t work with gtkmozembed, I remember  
trying  
to connect mouse signals, which isn’t supported.

> Thanks,  
> Alan

Cheers,  
Markus

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [April 4, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/gtkmozembed-ctrl-a/90468/3 "2007-04-04T16:06:14Z")

</div>

I have decided to write documentation for ruby-gnome2.

I am going to follow the model used at  
[TinyButStrong](http://www.tinybutstrong.com/examples.php). Of course my documentation  
project will be written with RoR. The examples in the left panel of the  
TBS site will be an iteration of a project to use the different features  
of ruby-gnome2. Obviously, I’ll have to use other parts of Gtk2 as  
well.

I have a lot of work to do before there will be any code released, but I  
will release all of my work as soon as I have anything to show.

I’m an experienced programmer and documentation writer, but a beginner  
with Ruby, so this is a very large project for me. I’d appreciate any  
advice (except the advice to quit), code snippets, explanations, etc.  
that you’d care to give to help shorten my learning curve / development  
time.

Regards,  
Alan L.

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys-and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
