So, I took a look at the source code, and it shouldn't be too hard... I can't do it. I can read C, but I can't write it easily. Anyway, it looks like everything can be hooked up.
This would benefit Hackety Hack a lot, if that's any motivation for you, _why. On Tue, Jul 7, 2009 at 7:12 PM, Devyn Cairns<[email protected]> wrote: > Sorry about being impatient, but I really need an answer to this. I'm > working on a game engine for Shoes, and it could benefit us all. > > On Mon, Jul 6, 2009 at 11:40 AM, Devyn Cairns<[email protected]> wrote: >> Thank you! The only problem with that is that it won't recognize two >> keys at once, and that is something to do with Shoes' keypress. I need >> to be able to detect both at once, so I need a native keydown. >> >> To _why, I think this would be even easier to put in than the original >> keypress was! Keydown/keyup is generally easier, isn't it? >> >> On Sun, Jul 5, 2009 at 10:12 AM, Ehsanul Hoque<[email protected]> wrote: >>> Oops, that para in the animate block makes it a bit slow sometimes, get rid >>> of that (was just for some troubleshooting). I'm talking about the 8th line >>> in the code. >>> >>> ________________________________ >>> Subject: RE: keydown? >>> From: [email protected] >>> Date: Sun, 5 Jul 2009 17:06:38 +0000 >>> To: [email protected] >>> >>> I've cooked up a hack that pretty much works. It's implemented in terms of >>> keypress events, relying on the fact that when you hold a key down, keypress >>> events are sent every 0.1s or so (at most), except the keypress after the >>> initial event/press, which takes 0.5 seconds to be sent (these figures are >>> on my machine anyways, for a barebones shoes app, you can adjust values >>> according to yours). >>> >>> The code takes account of the pause after the initial event, with the >>> disadvantage being that if you just press the button, it will assume it has >>> been held for a full 0.505 seconds. Which may be totally acceptable for a >>> lot of use cases. The other choice in this hack would be to wait for the >>> rapid events, but that would make it feel very sluggish. >>> >>> Also, I'm sure this could be abstracted out to look more like what you >>> wanted, a function where you passed in the key, but I leave that as an >>> exercise to someone who needs it. Here's the code: >>> >>> Shoes.app do >>> @info = para '' >>> @s = stack >>> @t = Time.now >>> animate( 10 ) do >>> if up_pressed? >>> @info.replace "You pressed UP!!!" >>> @s.append { para "up - ", Time.now.to_f%100, " - ", @t.to_f%100 } # >>> Check these paras to see the reason for problems >>> else >>> @info.replace "C'mon, you know you wanna press the up button, just do >>> it already" >>> end >>> end >>> keypress do |key| >>> if key.inspect == ':up' and Time.now - @t < 0.15 >>> # Continued press, where keypress events are fired off every ~0.1s >>> @t = Time.now >>> elsif key.inspect == ':up' and Time.now - @t >= 0.15 >>> # Initial press, which will followed by a second keypress event after >>> ~0.5s pause, if held down, hence the delay >>> @t = Time.now + 0.505 >>> end >>> end >>> def up_pressed? >>> # If the following statement is true, the up button is probably being >>> held down, since the last even fired less than 0.15s ago >>> Time.now - @t < 0.15 >>> end >>> end >>> >>> And this code should provide the timing of keypress events, in case they're >>> different for your hardware (also the events are slower if lots of things >>> are going on I guess, so you'd have to adjust the 0.15 values): >>> >>> Shoes.app do >>> @t = Time.now >>> keypress do |key| >>> para "\n" if Time.now - @t > 0.15 >>> para Time.now - @t >>> @t = Time.now >>> end >>> end >>> >>> >>>> Subject: keydown? >>>> From: [email protected] >>>> To: [email protected] >>>> Date: Sat, 4 Jul 2009 10:16:27 -0700 >>>> >>>> I want to be able to do this: >>>> >>>> kd = false >>>> animate 24 do >>>> kd = keydown?(:up) >>>> end >>>> >>>> Can we have keydown in some form or another? >>>> >>>> -- >>>> ~devyn >>> >>> ________________________________ >>> Insert movie times and more without leaving Hotmail®. See how. >>> ________________________________ >>> Windows Live™: Keep your life in sync. Check it out. >> >> >> >> -- >> ~devyn >> > > > > -- > ~devyn > -- ~devyn
