Skip to content

Commit 8cae0e3

Browse files
committed
GPU Display: Fix do not exit on arrow key presses in the console
1 parent 91cf226 commit 8cae0e3

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎GPU/GPUTracking/Global/GPUChainTracking.cxx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,12 @@ int32_t GPUChainTracking::RunChainFinalize()
860860
usleep(10000);
861861
if (GetProcessingSettings().runsStandalone) {
862862
iKey = kbhit() ? getch() : 0;
863+
if (iKey == 27 && kbhit()) { // Escape sequence (arrow keys, ...), not the ESC key
864+
while (kbhit()) {
865+
getch();
866+
}
867+
iKey = 0;
868+
}
863869
if (iKey == 27) {
864870
GetProcessingSettings().eventDisplay->setDisplayControl(2);
865871
} else if (iKey == 'n') {

‎GPU/GPUTracking/utils/linux_helpers.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ static inline int32_t getch()
2626
newt = oldt;
2727
newt.c_lflag &= ~(ICANON | ECHO);
2828
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
29-
int32_t retVal = getchar();
29+
unsigned char c;
30+
int32_t retVal = read(STDIN_FILENO, &c, 1) == 1 ? c : -1; // Not getchar(): its buffer would hide the remaining bytes from kbhit()
3031
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
3132
return (retVal);
3233
}

0 commit comments

Comments
 (0)