* How to get a key from keyboard @ 2008-11-28 15:20 tolkamp 2008-11-28 15:47 ` Gautier 0 siblings, 1 reply; 6+ messages in thread From: tolkamp @ 2008-11-28 15:20 UTC (permalink / raw) In Pascal there is a function Readkey to read a single character from the keyboard. Is there a simular function in ADA? I have tried the procedure Get_Immediate(Char, Error) but here you have to press the Enter key as well. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get a key from keyboard 2008-11-28 15:20 How to get a key from keyboard tolkamp @ 2008-11-28 15:47 ` Gautier 2008-11-29 6:15 ` Paul 0 siblings, 1 reply; 6+ messages in thread From: Gautier @ 2008-11-28 15:47 UTC (permalink / raw) tolkamp wrote: > In Pascal there is a function Readkey to read a single character from > the keyboard. Is there a simular function in ADA? NB: ReadKey is a Turbo Pascal thing. > I have tried the procedure Get_Immediate(Char, Error) but here you > have to press the Enter key as well. Strange... I get immediately each of "[a][b][c][d]..." when pressing each of "abcd...", with the following: -- with Ada.Text_IO; use Ada.Text_IO; procedure Test_Key is c: Character; begin loop Get_Immediate(c); Put('[' & c & ']'); end loop; end Test_Key; -- Compiled by GNAT, run on Windows. _________________________________________________________ Gautier's Ada programming -- http://sf.net/users/gdemont/ NB: For a direct answer, e-mail address on the Web site! ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get a key from keyboard 2008-11-28 15:47 ` Gautier @ 2008-11-29 6:15 ` Paul 2008-12-01 7:28 ` christoph.grein 0 siblings, 1 reply; 6+ messages in thread From: Paul @ 2008-11-29 6:15 UTC (permalink / raw) The other version of get_immediate works fine for me (GNAT GPL 2008) I always liked Turbo Pascal. It was my uni's "learning language" back in the mid 80's. Very fast on an 8086 computer! If I were going to use the code below I'd probably use the Look_Ahead procedure as well. I recall when I wrote some of this a while back that control codes and the like could be tricky. Paul with ada.text_io;use ada.text_io; procedure chartest is ch : character := 'Y'; available : boolean := false; begin put_line("Enter characters"); while ch /= 'X' loop get_immediate(ch, available); if available then put(ch); end if; end loop; new_line; put_line("Done"); end chartest; "Gautier" <gautier@fakeaddress.nil> wrote in message news:49301282$1_1@news.bluewin.ch... > tolkamp wrote: > >> In Pascal there is a function Readkey to read a single character from >> the keyboard. Is there a simular function in ADA? > > NB: ReadKey is a Turbo Pascal thing. > >> I have tried the procedure Get_Immediate(Char, Error) but here you >> have to press the Enter key as well. > > Strange... I get immediately each of "[a][b][c][d]..." when pressing each > of "abcd...", with the following: > -- > with Ada.Text_IO; use Ada.Text_IO; > > procedure Test_Key is > c: Character; > begin > loop > Get_Immediate(c); > Put('[' & c & ']'); > end loop; > end Test_Key; > -- > Compiled by GNAT, run on Windows. > _________________________________________________________ > Gautier's Ada programming -- http://sf.net/users/gdemont/ > > NB: For a direct answer, e-mail address on the Web site! ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get a key from keyboard 2008-11-29 6:15 ` Paul @ 2008-12-01 7:28 ` christoph.grein 2008-12-22 16:22 ` f.tolkamp 0 siblings, 1 reply; 6+ messages in thread From: christoph.grein @ 2008-12-01 7:28 UTC (permalink / raw) A.10.7 (9) procedure Get_Immediate(File : in File_Type; Item : out Character); procedure Get_Immediate(Item : out Character); (10) Reads the next character, either control or graphic, from the specified File or the default input file. Mode_Error is propagated if the mode of the file is not In_File. End_Error is propagated if at the end of the file. The current column, line and page numbers for the file are not affected. (11) procedure Get_Immediate(File : in File_Type; Item : out Character; Available : out Boolean); procedure Get_Immediate(Item : out Character; Available : out Boolean); (12) If a character, either control or graphic, is available from the specified File or the default input file, then the character is read; Available is True and Item contains the value of this character. If a character is not available, then Available is False and the value of Item is not specified. Mode_Error is propagated if the mode of the file is not In_File. End_Error is propagated if at the end of the file. The current column, line and page numbers for the file are not affected. Thus the former procedures block if there is no character available, the latter ones don't. Try: loop get_immediate (C); Put (Integer'Image (Character'Pos (c))); end loop; Which compiler do you use? If you run the above within GPS, you must press <enter> - otherwise GPS obviously does not forward the input to the executable (note that GPS echoes the input and you can edit the input line with <backspace>). If you run it from a terminal window, you can press any key and immediately get the result (for some keys, you'll get more than one number) and there is no echo of your input and no editing. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get a key from keyboard 2008-12-01 7:28 ` christoph.grein @ 2008-12-22 16:22 ` f.tolkamp 2008-12-22 17:40 ` Georg Bauhaus 0 siblings, 1 reply; 6+ messages in thread From: f.tolkamp @ 2008-12-22 16:22 UTC (permalink / raw) On 1 dec, 08:28, christoph.gr...@eurocopter.com wrote: > A.10.7 > (9) procedure Get_Immediate(File : in File_Type; > Item : out Character); > procedure Get_Immediate(Item : out Character); > > (10) Reads the next character, either control or graphic, from the > specified File or the default input file. Mode_Error is propagated if > the mode of the file is not In_File. End_Error is propagated if at the > end of the file. The current column, line and page numbers for the > file are not affected. > > (11) procedure Get_Immediate(File : in File_Type; > Item : out Character; > Available : out Boolean); > procedure Get_Immediate(Item : out Character; > Available : out Boolean); > > (12) If a character, either control or graphic, is available from the > specified File or the default input file, then the character is read; > Available is True and Item contains the value of this character. If a > character is not available, then Available is False and the value of > Item is not specified. Mode_Error is propagated if the mode of the > file is not In_File. End_Error is propagated if at the end of the > file. The current column, line and page numbers for the file are not > affected. > > Thus the former procedures block if there is no character available, > the latter ones don't. > > Try: > > loop > get_immediate (C); > Put (Integer'Image (Character'Pos (c))); > end loop; > > Which compiler do you use? If you run the above within GPS, you must > press <enter> - otherwise GPS obviously does not forward the input to > the executable (note that GPS echoes the input and you can edit the > input line with <backspace>). If you run it from a terminal window, > you can press any key and immediately get the result (for some keys, > you'll get more than one number) and there is no echo of your input > and no editing. Indeed I run the program within GPS, so the enter key have to be pressed. How can I run the program from a terminal window? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get a key from keyboard 2008-12-22 16:22 ` f.tolkamp @ 2008-12-22 17:40 ` Georg Bauhaus 0 siblings, 0 replies; 6+ messages in thread From: Georg Bauhaus @ 2008-12-22 17:40 UTC (permalink / raw) f.tolkamp@chello.nl wrote: > Indeed I run the program within GPS, so the enter key have to be > pressed. How can I run the program from a terminal window? Start a Windows terminal. In GPS, locate the project's objects directory. (You can find it in the "Objects" tab of the project properties.) In the terminal window, change directory to the project's objects directory. Run your program. When you have time, browse the GNAT User's Guide, linked from the GPS help menu. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-12-22 17:40 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-11-28 15:20 How to get a key from keyboard tolkamp 2008-11-28 15:47 ` Gautier 2008-11-29 6:15 ` Paul 2008-12-01 7:28 ` christoph.grein 2008-12-22 16:22 ` f.tolkamp 2008-12-22 17:40 ` Georg Bauhaus
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox