bensaward / game

Open source text based adventure game! See testing branch for most recent work!
0 stars 0 forks source link

Reading keys from outside ascii range #8

Open bensaward opened 11 years ago

bensaward commented 11 years ago

Reading characters from the keyboard which are outside of the ascii keys (eg the arrow keys) will most likely require a special function over getch(). This is because they return a 7 byte int, which is split into 3 chars. When using getch() only the last array is captured, the int returned overlaps with the ascii printing characters meaning that shift+letter can be used to move the cursor on the menu as it returns the same int through getch(). This is not a bug, more a special feature in the words of Linus.

Fix: ???

Use fgets to read from stdin. This should capture the whole array but the problem is that stdin is buffered and would require enter to be pressed often. Limit the size of the buffer written to, then search for the array?

The int is something like "\033[A" where the chars are '\033' '[' and 'A'. See "ANSI escape codes".

bensaward commented 11 years ago

http://forums.codeguru.com/showthread.php?523737-Detect-arrow-key-press-in-c-for-linux-only-80-of-the-job-is-done

Adapt this code