# How to get back focus on opening firefox via firewatir?

**URL:** <https://www.ruby-forum.com/t/how-to-get-back-focus-on-opening-firefox-via-firewatir/138474>\
**Category:** Ruby\
**Created:** [May 23, 2008, 11:55am UTC](https://www.ruby-forum.com/t/how-to-get-back-focus-on-opening-firefox-via-firewatir/138474 "2008-05-23T11:55:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@arun](https://www.ruby-forum.com/u/arun)\
**Post date:** [May 23, 2008, 11:55am UTC](https://www.ruby-forum.com/t/how-to-get-back-focus-on-opening-firefox-via-firewatir/138474/1 "2008-05-23T11:55:32Z")

</div>

Hi, I am writing software that will allow persons with severe motor  
disabilities – people who cannot use a full keyboard and mouse – to  
be able to use the Internet, an extension of what you see in

[![](https://img.youtube.com/vi/l7eMoA3cr8E/hqdefault.jpg "A child with cerebral palsy communicates via a wheel") ](https://www.youtube.com/watch?v=l7eMoA3cr8E)

Inputs from a joystick or a special keyboard are picked up by my  
program, interpreted, and fed to firefox using firewatir. No problems  
with the joystick program, but with the keyboard, there is a tiny one.

When I fire up Firefox, it takes focus, and eats up all my keystrokes.  
How can I get my terminal window to come to the foreground without  
manual intervention, so that my application gets keystrokes again?

On a related note, how do I, in ruby, reduce the size of the terminal  
window the program is running in, so that it does not obscure the  
firefox window underneath?

My program is as below…

Thanks,  
Arun

#!/usr/bin/env ruby  
require ‘rubygems’  
#Include the FireWatir file.  
require ‘firewatir’  
#include the FireWatir Module.  
include FireWatir  
begin  
th=Thread.new{system(‘script/server’)}  
sleep(3)  
ff=Firefox.new  
ff.goto(“[http://localhost:3000](http://localhost:3000)”)

# here is a loop that takes kbd input and passes on to ff until Ctrl-

C is pressed  
ensure  
ff.close  
th.terminate  
end
