Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

read from keyboard non blocking

Name: Anonymous 2010-10-05 6:56

hey there

is there a way to read from keyboard without breaking a program in C.

meaning if I use getchar the prog waits for new input from the keyboard but I want the program to be executed until it gets a stop character. I know I can use multi threading but is there s tutorial on something simpler?

Name: Anonymous 2010-10-05 6:57

hey

use getchat nonblocking. But that can be tricky, since judging but your post you do not know how to do it?

Name: Anonymous 2010-10-05 7:18

On unix-like systems:

man fcntl  to set NON BLOCKING on fd 0.

or use select() to check for available data

Name: Anonymous 2010-10-05 7:26

OP:

my program is not read file or anything else, I get some data from a micro controller and feed it back some acsii characters, I want the program to run all the time until stop key is pressed.

Everything else is done I just need to see how to make the loop non blocking until event

Name: Anonymous 2010-10-05 7:46

>>4
Read the thread. Then go back to India, code monkey.

Name: Anonymous 2010-10-05 8:15

I can't think of any solution, really, except your suggestion of using threads. If this was embedded programming, I'd simply keep polling the pin the button was connected to, but I don't know if it's even possible to poll the keyboard on a PC. At a guess, I'd say that would be OS specific. It sure isn't anywhere in the C standard, but I'm reasonably sure a solution could be found somewhere in POSIX, not that I'd know where to look.

Name: Anonymous 2010-10-05 8:34

>>6
IHBT

Name: Anonymous 2010-10-05 8:45

Use polling, that's how it's always been done, since even the DOS days.

Name: Anonymous 2010-10-05 9:37

personally i'd write some inline assembly to read from whatever hardware port the keyboard is connected to. keep checking the buffer for a change...

OR, i'd use the bios interrupt 16h, subfunction 01h
something like

recheck:
mov ax, 01h
int 16h
jz recheck

keywaspressed:

Name: Anonymous 2010-10-05 10:43

>>9
You're not qualified to answer this question. I hope I never have to use any software you've written.

Name: Anonymous 2010-10-05 11:13

>>10
Fuck you. Assembly is superior to any programming language.

Name: Anonymous 2010-10-05 11:28

>>11
LDAP your anus, ``faggot''

Name: Anonymous 2010-10-05 13:05

fork();

Or, alternatively:

readFromKeyboardWithoutInterrupingExecutionFlow(dpKeyBuf, yjLost, daGame, SECURITY_PERMISSION_READ_KEYBOARD, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);

Name: Anonymous 2010-10-05 13:20

>>13
You missed a NULL.

Name: Anonymous 2010-10-05 19:14

I think he missed two, actually.

ANYway, we ended up doing it by using getchar in one thread and having the engine control function running in a different thread.

Name: Anonymous 2010-10-05 19:25

>>15
I wish you knew how intensely disappointed I am with you.

Name: Anonymous 2010-10-05 20:04

>>15
Ah multithreading, tool of the ignorant

Name: Anonymous 2010-10-05 21:01

>>17
Ah multithreading, tool of the tool

Name: Anonymous 2010-10-06 3:45

Ah multithreading, multi of the threading

Name: Anonymous 2010-12-22 9:04


Don't change these.
Name: Email:
Entire Thread Thread List