Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pressing the Enter key instead of Clicking button with Shoes (Ruby)

Tags:

ruby

shoes

As the title suggests, I'm just looking for a way of pressing a button in Shoes without clicking it.

I've searched the forum, but unfortunately can't find anything.

Thanks

like image 690
Josh Avatar asked Aug 19 '11 13:08

Josh


2 Answers

that won't work in red shoes under windows since the windows controlls steal all the events. I managed to get this at work in green shoes under windows though.

Here an example

['green_shoes'].each(&method(:require))
Shoes.app{
  e = edit_line
  button("Click me!"){alert("You clicked me.")}
  keypress { |k| alert("You pressed Enter") if k == "\n"}
}

Grtz

like image 93
peter Avatar answered Oct 05 '22 23:10

peter


I do not have shoes at the moment, but I believe you could trap the keypress and execute its action like so:

button('Click me') { do_something }

keypress { |k| do_something if k == '\n' }

From the manual:

One caveat to all of those rules: normally the Return key gives you a string "\n". When pressed with modifier keys, however, you end up with :control_enter, :control_alt_enter, :shift_alt_enter

like image 34
Eduardo Sampaio Avatar answered Oct 06 '22 00:10

Eduardo Sampaio