tags:

views:

92

answers:

1
Shoes.app do
 keypress do |k|
    if k==:f1
      alert("Foo bar")
    end
  end
  button "foo"
end

Pressing F1 causes the alert box to pop up but. Once i click the button "foo" i.e. if the focus changes to a native control in the app. the keypress events are no longer captured. any way to get around it?

I am using windows xp.

+2  A: 

This is still a bug in Shoes on Windows at the time of writing. If you can get away with doing a clear and redrawing everything you can get the keypress events back again, e.g:

Shoes.app do
    def drawbutton
        @holder.clear do
            button "foo" do
                drawbutton
            end
        end
    end

    @holder = stack 

    drawbutton

    keypress do |k|
        if k==:f1
            alert("Foo bar")
        end
    end
end

Although this trick works for the example in your question, I'm not sure it would translate well to a real app.

i5m