Tuesday, October 20, 2009

overloading SEL_KEYPRESS

Or something like that...

The idea is to get some widget to do not only what it's supposed to, but also something else. For example, I would really want to hear the buzzing sound of a fly whenever I press Ctrl-z in some FXText.
  1. require 'fox16'
  2. require 'fox16/responder'
  3. include Fox

  4. class BuzzingText < FXText

  5.   include Responder

  6.   def initialize p
  7.     super p
  8.     FXMAPFUNC(SEL_KEYPRESS, 0, :onKeyPress)
  9.   end

  10.   def onKeyPress sender, sel, event
  11.     super sender, sel, event
  12. if (event.state & CONTROLMASK != 0) and (event.code == KEY_z)
  13.       # buzz
  14. end
  15.   end

  16. end

No comments:

Post a Comment