[fxruby-users] Problem detecting keypresses in FXTable

William B. Parsons wbparsons at cshore.com
Sun Apr 11 19:29:28 EDT 2010

On Fri, 9 Apr 2010 18:25:00 -0700 (PDT)
dave L <dglnz at yahoo.com> wrote:

> Shouldn't it be FXTable.connect(Fox::SEL_KEYRELEASE) do |sender, selector, event|
> I use foxGUIb so if i am wrong i stand corrected to others who know better.

No, I think the syntax is correct - after all, it does work as expected after a mouse
click on a table cell.  Here's a small test program to illustrate the problem:

#!/usr/bin/env ruby
require 'fox16'
include Fox

class TopLevelWindow < FXMainWindow
   def initialize(app)
      super(app, 'Test', :width => 420, :height => 150)

      frame = FXVerticalFrame.new(self, :opts => FRAME_SUNKEN|LAYOUT_FILL)
      table = FXTable.new(frame, :opts => LAYOUT_FILL)
      table.setTableSize(5, 3)
      table.connect(SEL_SELECTED) do |sender, selector, data|
         if data.col == 0
            puts "row #{data.row} selected"
      table.connect(SEL_KEYPRESS) do |sender, selector, event|
         puts "code = #{'%X' % event.code}"

   def create

app = FXApp.new(ARGV[0])

# kick off application


After selecting a row initially, keypresses (or releases) are not dectected until there
is a mouse click within a cell, after which key presses/releases are detected.

What I want to do - select a row and then press to Del/Delete key to delete it - I would
think would a fairly common thing to want to do when dealing with tables.  Haven't other
people come across this issue?

> From: Will Parsons <wbparsons at cshore.com>
> To: fxruby-users at rubyforge.org
> Sent: Sat, 10 April, 2010 8:59:14 AM
> Subject: [fxruby-users] Problem detecting keypresses in FXTable
> I'm using an RXTable in my application and I would like to be able to
> select a row and then press the Delete key to delete the selected row.
> This does not seem to work, however, as apparently keypresses are not
> initially recognized.  In my FXTable derived class I have:
>    connect(SEL_KEYRELEASE) do |sender, selector, event|
>       puts "code = #{'%X' % event.code}"
>       case event.code
>          when KEY_Delete, KEY_KP_Delete
>             puts "Delete key hit"
>             # process...
>          # ...
>       end
>    end
> When I left-click on a row header, the row gets properly selected and
> highlighted, but hitting any key does not result in being recognized
> (i.e., the messages above do not appear).  If I then click on a table
> cell, then subsequent keypresses cause the connected code to fire, and
> things work as expected.  Do I have to do something to receive key
> events initially?

William B. Parsons <wbparsons at cshore.com>

More information about the fxruby-users mailing list