Getch() Problem: C vs D

Ivan Kazmenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 9 10:09:21 PST 2017


On Monday, 9 January 2017 at 17:22:41 UTC, LouisHK wrote:
> On Monday, 9 January 2017 at 13:10:30 UTC, Adam D. Ruppe wrote:
>> ...
>> Best solution is to skip those C library functions and do it 
>> yourself with the OS-level calls. Then you can turn it off and 
>> actually control the buffering behavior.
>
> That's what I was afraid of. I even tried your terminal.d, and 
> it worked for those keys above, but unfortunately it's 
> duplicating the values, one little example (From your source):
>
> if(input.kbhit()){
>     auto c = input.getch();
>     write(c);
> }
>
> As I could see with WinDBG, the condition "input.kbhit()" is 
> true for the first 2 times after I hit a key.

That's because special keys actually put two characters in the 
buffer, right?  Otherwise, using that buffer alone, you won't be 
able to distinguish, for example, arrow keys from capital Latin 
letters with the same codes.



More information about the Digitalmars-d-learn mailing list