Frage

fragte sich, wie Sie den Eingang testen können, der in einem Zeichen in einem Zeichen gespeichert ist ... generasacodicetagpre.

und mit generasacodicetagpre.

, um die Eingabe vom Benutzer zu erhalten, aber fragte sich, wie ich eine IF-Anweisung verwenden könnte, um zu testen, ob die Eingabe des Benutzers zum Beispiel vorhanden ist ctrl + d oder beliebige ctrl + anykey?

Ich habe versucht, dort ASCCI-Wert so zu verwenden. generasacodicetagpre.

Ergebnis ist ein char-array aswell.

War es hilfreich?

Lösung

You can only test Ctrl+d as your read returning EOF, see the manual of your read to have more info on this, but generally it returns 0. Same goes for Ctrl+c, as both are sending signals to your program.

For other Ctrl+key combinations, it highly depends on your system.

On linux Ctrl+a and Ctrl+e in a shell or emacs will move you to the beginning or the end / beginning of the line respectively.

The easiest to get what you want is to write a small program using read, unbuffered (see ioctl), with a 8-bytes buffer, and dump your read bytes each time you exit the read.

int nbr;
int i;
char buf[8];

nbr = 42;
while (nbr > 0)
{
  nbr = read(0, buf, 8);
  i = 0;
  while (i < nbr)
    printf("%x ", buf[i++]);
  printf("\n");
}

You will have the hex version of the ctrl+key received sequences. Likely to begin with \ESC or \033 (the escape character sequence). For example the arrow-up key looks like \033[A

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top