1

I need to read keys from stdin without blocking, and without only recieving them when a newline is pressed. The way i would like it be formatted is a sequence, where each item is a keypress or ascii char, of every key pressed since the last time I called this procedure.

I tried the following code:

while true:
    let ch = readChar(stdin)
    echo ch

but the keys are only recieved after I press a newline, and then they come in 1 by 1.

1 Answer 1

0

Have you tried to https://github.com/johnnovak/illwill ?

Something like :

import os, illwill

illwillInit()

while true:
  var key = getKey()
  case key
  of Key.None: discard
  of Key.Escape, Key.Q:
    break
  else:
    echo "Key pressed: ", $key
  
  sleep(20)
1
  • You might also want to look into termkey (but I never used it)
    – Clonk
    Commented Jun 18 at 12:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.