6

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

Josh
  • 175
  • 10
  • 1
    I can definitely see why you'd prefer to use your fingers to press the ENTER key rather than have to lift your leg to click a button with your shoe. (Alas, I can't help you with your question, though!) – ewall Aug 19 '11 at 13:51
  • Lol, thanks! Not quite what I was after though. – Josh Aug 22 '11 at 11:53
  • Could you clarify: are you trying to click the button programmatically based on any other criteria/events, or are you trying to specifically have the Enter key work only when that button is focused? – Phrogz Oct 10 '11 at 16:16
  • So as an example, when you enter your details into a website, you type Username password That's what I'm getting at. – Josh Nov 28 '11 at 16:49

2 Answers2

1

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

Eduardo Sampaio
  • 589
  • 6
  • 15
1

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

peter
  • 41,770
  • 5
  • 64
  • 108
  • Oh, do you have an example of how you did it with Green Shoes? – Josh Dec 22 '11 at 16:32
  • I edited my answer to include an example, sorry it took so long, forgot this thread, BTW, there is a new version of Green Shoes, check it out ! – peter Jan 02 '12 at 13:57
  • Perfect! Thanks, I'll just have to re-write my app to use Green Shoes! – Josh Feb 03 '12 at 14:45