Can anyone tell me how to get a single character from the command line
prompt without the user pressing ? This would be in response
to a Yes/No question or a number from a simple printed menu.
I did notice something in my “The Ruby Way” book which talked about
the feature being in TK. Is there nothing in standard Ruby?
Can anyone tell me how to get a single character from the command line
prompt without the user pressing ? This would be in response
to a Yes/No question or a number from a simple printed menu.
I did notice something in my “The Ruby Way” book which talked about
the feature being in TK. Is there nothing in standard Ruby?
…but I have a question about your use of kbhit() and sleep(). I
assume that while my code is waiting, Windows will still allocate time
slices for other programs that might be running at the same time.
Does using kbhit() and sleep() allow time to be given to other threads
that may be running concurrently in the same Ruby program as the
_getch()?
Can anyone tell me how to get a single character from the command line
prompt without the user pressing ? This would be in response
to a Yes/No question or a number from a simple printed menu.
I did notice something in my “The Ruby Way” book which talked about
the feature being in TK. Is there nothing in standard Ruby?
Hmmmm. This worked ok in my little test file, but the character is
still in a buffer somewhere. In my program, I hit ‘n’ to not do
something, then ‘puts’ to the command line with no problem – then
when I do a ‘gets’ the ‘n’ prints out. What the heck?
Usano
require ‘Win32API’
print "Question? (Y/N): "
char = Win32API.new(‘crtdll’, “_getch”, [], ‘L’).Call
putc char
putc ?\n
if [?y,?Y].include? char
puts "You pressed ‘Y’"
else
puts "You pressed something other than ‘Y’"
end
gets # this prints the ‘y’ or ‘n’ !!!
…but I have a question about your use of kbhit() and sleep(). I
assume that while my code is waiting, Windows will still allocate time
slices for other programs that might be running at the same time.
Does using kbhit() and sleep() allow time to be given to other threads
that may be running concurrently in the same Ruby program as the
_getch()?
Can anyone tell me how to get a single character from the command line
prompt without the user pressing ? This would be in response
to a Yes/No question or a number from a simple printed menu.
I did notice something in my “The Ruby Way” book which talked about
the feature being in TK. Is there nothing in standard Ruby?
Im not understanding what the problem is? I tried the script and seems
to work like its suppost to. maybe your using doskey?
AW
Usano wrote:
···
Hmmmm. This worked ok in my little test file, but the character is
still in a buffer somewhere. In my program, I hit ‘n’ to not do
something, then ‘puts’ to the command line with no problem – then
when I do a ‘gets’ the ‘n’ prints out. What the heck?
Usano
require ‘Win32API’
print "Question? (Y/N): "
char = Win32API.new(‘crtdll’, “_getch”, , ‘L’).Call
putc char
putc ?\n
if [?y,?Y].include? char
puts “You pressed ‘Y’”
else
puts “You pressed something other than ‘Y’”
end
gets # this prints the ‘y’ or ‘n’ !!!