How to detect any keyboard button pressed in Ada language

424 views Asked by At

I am a beginner in Ada programming. I am trying to make a "2048" game using Ada. I did "2048" in C++, and I used "kbhit()" to detect that is there any keyboard button pressed. I want to know that is there any similar function available like "kbhit()" in Ada, or how to write a function to detect is there any keyboard button pressed, or should I just use the function by interface in C++.

1

There are 1 answers

1
Keith Thompson On

Yes, you can use any of several overloaded versions of Ada.Text_IO.Get_Immediate. The declarations are (copied from the 2012 edition of the Ada standard):

procedure Get_Immediate(File : in File_Type;
                        Item : out Character);
procedure Get_Immediate(Item : out Character);

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.

procedure Get_Immediate(File : in File_Type;
                        Item : out Character;
                        Available : out Boolean);
procedure Get_Immediate(Item : out Character;
                        Available : out Boolean);

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.