Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

kbhit()

 [1/17] from: holger::rebol::com at: 22-Jun-2001 13:12


On Fri, Jun 22, 2001 at 12:18:52PM -0700, Jeff Kreis wrote:
> What are you trying to do, Holger? > One up me or something??? > ;-)
*grin*
> > con: open/direct/binary/no-wait console:// > > until [wait con]
<<quoted lines omitted: 3>>
> Gahh.. huh?? Above's a busy loop, especially with no-wait, eh? > Above loops away waiting for a single char.
No. /no-wait just means that 'copy does not block. No busy-wait there.
> to-char first wait open/direct/binary console:// > > Above waits (no loop) for a single char and returns it.
Yes, but assuming that wait always returns the port you are waiting for is not quite safe, in particular not in future versions of REBOL where background port handlers can trigger a 'wait wakeup based on some event... Having the 'until around it is safer. -- Holger Kruse [holger--rebol--com]

 [2/17] from: jeff:rebol at: 22-Jun-2001 13:28


> Yes, but assuming that wait always returns the port you are > waiting for is not quite safe, in particular not in future > versions of REBOL where background port handlers can > trigger a 'wait wakeup based on some event... Having the > 'until around it is safer.
Holger, we need a how to work with ports in a future compatible way how-to. I think I need to read it. *grin* -jeff

 [3/17] from: louisaturk:eudoramail at: 22-Jun-2001 17:58


Thanks, Holger and Jeff, This is what I wanted: REBOL [] kbhit: func [][ con: open/direct/binary/no-wait console:// until [wait con] choice: to-char pick con 1 ] forever [ ;ask "Press the lower case x key." <====<<< This won't work. print "Press the lower case x key." choice: kbhit print choice if choice = #"x" [print "It works!"] ] Took me awhile to learn how to use your code. I was using ask instead of print in the line above. :>) Stayed up too late last night! Many thanks again for all the help. I really need this function, as I use it often. I hate typing two key when one keystroke will do. Louis At 11:57 AM 6/22/2001 -0700, you wrote:

 [4/17] from: louisaturk:eudoramail at: 22-Jun-2001 14:00


Hi Jeff, That might be what I want. However, if I type "x" I get:
>> choice: until[input?]
== true
>> x
** Script Error: x has no value ** Where: halt-view ** Near: x
>> choice
== true How do I get x into the variable instead of true? Louis At 10:05 AM 6/22/2001 -0700, you wrote:

 [5/17] from: jeff:rebol at: 22-Jun-2001 11:24


Howdy, Louis:
> That might be what I want. However, if I type "x" I get: >> choice: until[input?]
<<quoted lines omitted: 4>>
> == true > How do I get x into the variable instead of true?
con: open/direct/binary [scheme: 'console] until [wait .02 input?] choice: pick con 1 Holger, can you use set-modes to change the existing console port attributes? -jeff

 [6/17] from: jeff:rebol at: 22-Jun-2001 11:41


> con: open/direct/binary [scheme: 'console] > until [wait .02 input?] choice: pick con 1
oops.. choice: to-char pick con 1 (the wait .02 prevents busy looping -- and keeps your view events working *TRANSPARENTLY*!!! (-: ) -jeff

 [7/17] from: holger:rebol at: 22-Jun-2001 11:40


On Fri, Jun 22, 2001 at 11:24:59AM -0700, Jeff Kreis wrote:
> con: open/direct/binary [scheme: 'console] > until [wait .02 input?] choice: pick con 1 > > Holger, can you use set-modes to change the existing console > port attributes?
Yes, but the problem with that is that if your script produces an error and you drop to the console your settings may be messed up. Opening another port as you are doing is safer. -- Holger Kruse [holger--rebol--com]

 [8/17] from: louisaturk:eudoramail at: 22-Jun-2001 14:53


Hi again Jeff, Now if I type "x" I get:
>> con: open/direct/binary [scheme: 'console] >> until [wait .02 input?] choice: pick con 1
== 120
>> choice
== 120
>>
How did my x become 120? Louis At 11:24 AM 6/22/2001 -0700, you wrote:

 [9/17] from: holger:rebol at: 22-Jun-2001 11:57


On Fri, Jun 22, 2001 at 11:41:23AM -0700, Jeff Kreis wrote:
> > con: open/direct/binary [scheme: 'console] > > until [wait .02 input?] choice: pick con 1 > > oops.. > > choice: to-char pick con 1 > > (the wait .02 prevents busy looping -- and keeps your view > events working *TRANSPARENTLY*!!! (-: )
Why not con: open/direct/binary/no-wait console:// until [wait con] choice: to-char pick con 1 No crazy poll loops needed :-). -- Holger Kruse [holger--rebol--com]

 [10/17] from: jeff:rebol at: 22-Jun-2001 12:18


What are you trying to do, Holger? One up me or something??? ;-)
> Why not > > con: open/direct/binary/no-wait console:// > until [wait con] > choice: to-char pick con 1 > > No crazy poll loops needed :-).
Gahh.. huh?? Above's a busy loop, especially with no-wait, eh? Above loops away waiting for a single char. to-char first wait open/direct/binary console:// Above waits (no loop) for a single char and returns it. Presumably someone wants kbhit because they want to make a spaceship game, so you *want* to poll. REBOL [ Title: "Spaceship game framework" ] conn: open/direct/binary/no-wait console:// ;-- returns false otherwise do input?-val: has [c][if c: wait conn [to-char first c]] forever [ if c: input?-val [ switch/default c [ #"z" [fire-missile] #"q" [quit] #"s" [toggle-sound] ... ][default-case] ] make-other-ships-move-and-stuff wait .02 ]

 [11/17] from: dness:home at: 22-Jun-2001 15:27


Dr. Louis A. Turk wrote:
> Hi again Jeff, > Now if I type "x" I get:
<<quoted lines omitted: 6>>
> How did my x become 120? > Louis
120 is the ascii code for lower-case x...

 [12/17] from: joel:neely:fedex at: 22-Jun-2001 14:28


Perhaps?
>> to-char 120
== #"x"
>> to-char 120
== #"x" Now as to why??? ... Dr. Louis A. Turk wrote:
> Hi again Jeff, > Now if I type "x" I get:
<<quoted lines omitted: 5>>
> >> > How did my x become 120?
-- It's turtles all the way down! joel'dot'neely'at'fedex'dot'com

 [13/17] from: louisaturk:coxinet at: 22-Jun-2001 4:51


Does rebol have a kbhit() function? Louis

 [14/17] from: jeff:rebol at: 22-Jun-2001 10:05


Howdy, Louis:
> Does rebol have a kbhit() function?
try this at the console: until [input?] print "Thanks for the input."

 [15/17] from: g:santilli:tiscalinet:it at: 23-Jun-2001 15:47


Hello Dr.! On 23-Giu-01, you wrote: DT> kbhit: func [][ DT> con: open/direct/binary/no-wait console:// DT> until [wait con] DT> choice: to-char pick con 1 DT> ] This looks better:
>> kbhit: does [to-string read/binary/wait console://] >> kbhit
== "x" ; pressed x
>> kbhit
== "^[[A" ; pressed up arrow To Holger: will this have problems in the future? Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [16/17] from: arolls:bigpond:au at: 24-Jun-2001 1:27


> DT> kbhit: func [][ > DT> con: open/direct/binary/no-wait console://
<<quoted lines omitted: 8>>
> == "^[[A" ; pressed up arrow > To Holger: will this have problems in the future?
It has problems now! :) In latest Rebol/View 1.2.1, 'read has no refinement "/wait". I modified it like this: kbhit: does [to-string read/binary/part console:// 1] which works a little bit strange with arrow keys etc:
>> kbhit
== "^["
>> [A ; pressed up arrow
but works ok for other keys:
>> ch: kbhit
== "d" ; pressed "d" key Anton.

 [17/17] from: g:santilli:tiscalinet:it at: 24-Jun-2001 12:22


Hello Anton! On 23-Giu-01, you wrote: A> It has problems now! :) A> In latest Rebol/View 1.2.1, 'read has no refinement "/wait". Ooops, sorry, I was playing with /Core on the Amiga and I see I still have 2.3 here (time to upgrade, huh? :). A> kbhit: does [to-string read/binary/part console:// 1] I wanted to avoid /part exactly for the reason you show below. We'll have to resort to: kbhit: does [ con: open/binary/no-wait console:// until [wait con] first reduce [to-string copy con close con] ] which seems to work as expected. Sorry for wasting your time with my previous post... Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted