[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Non blocking keypress reading?

Sard Aukary

9/8/2006 11:42:00 AM

On Windows XP is there a way to test that a certain key has been pressed
without blocking?

Iâ??ve tried using curses but it blocks the current thread and any other
thread until a key is pressed.


I want to give the user 10 seconds so make a selection before a default
action is taken.

Here is the test code Iâ??ve got;


require 'curses'
include Curses
init_screen
noecho
trap(0) { echo }

t1 = Time.new
Thread.new do

#example timer thread
while(true) do
x = Time.new - t1
h = 3+3
setpos(12,10)

addstr("#{x}")

end
end

setpos(1,5)
addstr("Please select your location")
setpos(3,5)
addstr(" 1 - Work")
setpos(4,5)
addstr(" 2 - Home")
setpos(6,5)
addstr("Esc - Exit")
while (c = getch) != ?\e do
# check what key is pressed and do stuff
end

--
Posted via http://www.ruby-....

5 Answers

William Crawford

9/8/2006 11:52:00 AM

0

Sard Aukary wrote:
> On Windows XP is there a way to test that a certain key has been pressed
> without blocking?

From my quick search, I didn't find a way. Maybe this will help though?

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby...

--
Posted via http://www.ruby-....

Jano Svitok

9/8/2006 12:01:00 PM

0

On 9/8/06, Sard Aukary <sardaukary@yahoo.co.uk> wrote:
> On Windows XP is there a way to test that a certain key has been pressed
> without blocking?
>
> I've tried using curses but it blocks the current thread and any other
> thread until a key is pressed.
>
>
> I want to give the user 10 seconds so make a selection before a default
> action is taken.
>
> Here is the test code I've got;
>
>
> require 'curses'
> include Curses
> init_screen
> noecho
> trap(0) { echo }
>
> t1 = Time.new
> Thread.new do
>
> #example timer thread
> while(true) do
> x = Time.new - t1
> h = 3+3
> setpos(12,10)
>
> addstr("#{x}")
>
> end
> end
>
> setpos(1,5)
> addstr("Please select your location")
> setpos(3,5)
> addstr(" 1 - Work")
> setpos(4,5)
> addstr(" 2 - Home")
> setpos(6,5)
> addstr("Esc - Exit")
> while (c = getch) != ?\e do
> # check what key is pressed and do stuff
> end

search the archive for kbhit

Michael Fellinger

9/11/2006 9:53:00 AM

0

On Friday 08 September 2006 20:42, Sard Aukary wrote:
> On Windows XP is there a way to test that a certain key has been pressed
> without blocking?
>
> I’ve tried using curses but it blocks the current thread and any other
> thread until a key is pressed.
>
>
> I want to give the user 10 seconds so make a selection before a default
> action is taken.

require 'timeout'
begin
  Timeout.timeout(10) do
    key = gets
  end
rescue Timeout::Error
  key = default
end

>
> Here is the test code I’ve got;
>
>
> require 'curses'
> include Curses
> init_screen
> noecho
> trap(0) { echo }
>
> t1 = Time.new
> Thread.new do
>
> #example timer thread
> while(true) do
> x = Time.new - t1
> h = 3+3
> setpos(12,10)
>
> addstr("#{x}")
>
> end
> end
>
> setpos(1,5)
> addstr("Please select your location")
> setpos(3,5)
> addstr(" 1 - Work")
> setpos(4,5)
> addstr(" 2 - Home")
> setpos(6,5)
> addstr("Esc - Exit")
> while (c = getch) != ?\e do
> # check what key is pressed and do stuff
> end

--
Weez International Limited

East Roppongi Bldg 5F, 509
3-16-35 Roppongi, Minato-ku Tokyo #106-0032
Tel: 81-(0)3-3505-3881 Fax: 81-(0)3-3505-3883
E-mail: manveru@weez-int.com
Website: http://we...

andy-uk

9/15/2012 9:36:00 PM

0

http://soundcloud.com/andy-pattinson/pas...

http://soundcloud.com/andy-pattinson/pas...

Here are two versions of pasta blues (from virtuoso #3) as you can tell they are in one take ;)... USE HEADPHONES NOT LAPTOP SPEAKERS :)

andy-uk

9/15/2012 9:48:00 PM

0

http://soundcloud.com/andy-pattinson/pas...

here is second link.. you would not believe the b.s. you have to go through to record and upload an mp3 .