J
John Reye
Hello,
how can one create a program, that runs some "timer controlled
process", which is influenced by keypresses?
Example:
============
The program reads a file like:
1.5 car
3.4 kitchen
10.7 fish
and then accordingly the program will :
* prints "car", waits for 1.5 seconds
* prints "kitchen", waits for 3.4 seconds
etc.
And while this is running, I want the user to be able to skip forward
or backwards by hitting the keyboard keys
* hit 'n' for next -- immediately print the next word
* hit 'p' for previous -- print the previous word (or the same word
again, if we're already on the first word)
===============
My questions:
1) can this be done is standard c, or will the code be platform-
specific? (I'm running Linux)
2) does one need threads, in order to handle the keypress-detection
running in parallel with the "timer controlled process", or can it be
done without threads?
3) Can one harness some interrupt mechanism (or related mechanism) to
solve this? E.g. can the keypresses be detected as interrupts in a
userland linux program?
Thanks for hints and your help.
Pointers to related code-snippets are welcome.
J.
how can one create a program, that runs some "timer controlled
process", which is influenced by keypresses?
Example:
============
The program reads a file like:
1.5 car
3.4 kitchen
10.7 fish
and then accordingly the program will :
* prints "car", waits for 1.5 seconds
* prints "kitchen", waits for 3.4 seconds
etc.
And while this is running, I want the user to be able to skip forward
or backwards by hitting the keyboard keys
* hit 'n' for next -- immediately print the next word
* hit 'p' for previous -- print the previous word (or the same word
again, if we're already on the first word)
===============
My questions:
1) can this be done is standard c, or will the code be platform-
specific? (I'm running Linux)
2) does one need threads, in order to handle the keypress-detection
running in parallel with the "timer controlled process", or can it be
done without threads?
3) Can one harness some interrupt mechanism (or related mechanism) to
solve this? E.g. can the keypresses be detected as interrupts in a
userland linux program?
Thanks for hints and your help.
Pointers to related code-snippets are welcome.
J.