# Capture keyboard input without window focus

**URL:** <https://www.ruby-forum.com/t/capture-keyboard-input-without-window-focus/161479>\
**Category:** Ruby-Gnome 2\
**Created:** [February 26, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/capture-keyboard-input-without-window-focus/161479 "2009-02-26T20:09:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgoetzin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/edb3f5/32.png) [@pgoetzin](https://www.ruby-forum.com/u/pgoetzin)\
**Post date:** [February 26, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/capture-keyboard-input-without-window-focus/161479/1 "2009-02-26T20:09:09Z")

</div>

Hello everyone,  
i need a suggestion, i have a GTK app that start without a window when i  
press shift+ctr+p a window should be shown.

My current try is like follow its not really nice but its nearly working  
😃

The code below is only working when the focus/cursor is on a window this  
is not possible because its hidden, is there a opportunity to catch it  
global from X ? or do i need a dummy window in the background ?

Gtk.key\_snooper\_install{|w, e|  
@key\_input.push e.hardware\_keycode  
#puts “code=#{e.hardware\_keycode}”  
#puts “l =#{@key\_input.length}”

$SCHEDULER.in(1){@key\_input.clear}  
@key\_input.clear unless([33,37,64].include? e.hardware\_keycode or  
@key\_input.length \< 4)

if @key\_input.include?(33) and @key\_input.include?(37) and  
@key\_input.include?(64) then

```
   # show cusor that was hidden
   $login.root_window.set_cursor(
                    Gdk::Cursor.new(Gdk::DisplayManager.get.default_display,
                                    Gdk::Cursor::ARROW)
   )
   #do my action / unhide my window
   window.show_all...

```

end

thanks ahead!

kind regards

Philipp
