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

2

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

Cleanse answered 19/8, 2011 at 13:29 Comment(4)
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!)Divan
Lol, thanks! Not quite what I was after though.Cleanse
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?Jamieson
So as an example, when you enter your details into a website, you type Username <tab> password <enter> That's what I'm getting at.Cleanse
E
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

Enthusiastic answered 16/12, 2011 at 11:47 Comment(3)
Oh, do you have an example of how you did it with Green Shoes?Cleanse
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 !Enthusiastic
Perfect! Thanks, I'll just have to re-write my app to use Green Shoes!Cleanse
N
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

Nolte answered 5/10, 2011 at 18:26 Comment(0)
E
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

Enthusiastic answered 16/12, 2011 at 11:47 Comment(3)
Oh, do you have an example of how you did it with Green Shoes?Cleanse
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 !Enthusiastic
Perfect! Thanks, I'll just have to re-write my app to use Green Shoes!Cleanse

© 2022 - 2024 — McMap. All rights reserved.