cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to distinguish arrow-key from escape character with getch in C?

missyT
New Contributor III

I want to know weather an arrow key or the escape character has ben pressed. But in order to check which arrow key has been pressed I need to do multiple blocking getch-calls bc the arrow-key sequence is bigger than 1 char. This is a problem when I check for the escape char bc it only needs 1 char and this first char is identical to the one arrow returns. So I call the first getch which gets the escape character but afterwards I have to call getch two more times to check its not an arrow-key. Is there a way to know weather escape has been pressed without doing two more getch-calls afterwards to check for the arrow-keys <a href = "https://azar.pro"> Azar </a>?

<a href = "https://chatrandom.download/"> Chatrandom </a>

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

getch () function returns two keycodes for arrow keys. Arrow put to getch '\033'

and '[' and letter from A to D (up, down, right, left) so code will be something like:

if (getch() == '\033')  { 
    getch(); // [ value
    switch(getch())
    { 
        case 'A':
            // your code
        case 'B':
            // your code
        case 'C':
            //your code
        case 'D':
            //your code
    }
}

View solution in original post

1 REPLY 1

Hubert-Dudek
Esteemed Contributor III

getch () function returns two keycodes for arrow keys. Arrow put to getch '\033'

and '[' and letter from A to D (up, down, right, left) so code will be something like:

if (getch() == '\033')  { 
    getch(); // [ value
    switch(getch())
    { 
        case 'A':
            // your code
        case 'B':
            // your code
        case 'C':
            //your code
        case 'D':
            //your code
    }
}

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group