Thread: How to receive i/o "events" in C?

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    How to receive i/o "events" in C?

    Hello I am looking for a way to do I/O event programming with keyboard (and possibly mouse) in C. I've looked for quite some time and I can't find a straightforward or consistent answer on the topic. Obviously there must be a contrived way at least of doing it. Or else how could other languages which were built on or compiled with C have I/O events? What I'm currently building/learning is to build a chat server and I want it so the user (or server) can press "escape" on the keyboard and kill their client or server. Or press another key for some other even I may put into the program. I am trying to expand my knowledge of C, Unix, networking, and event handling for other purposes. I want to see if there is any way of using standard C to do this if possible. And, as if I need to add more problems, this needs to be asynchronous. I can't have my program blocked (or at least not appear to be blocked to the user) polling all the time for keyboard press. So any help here would be hot! Thanks!

  2. #2
    spaghetticode
    Guest
    First off, I am a beginner and am not familiar with topics like this one. But as far as my understanding has developed by now, I don't believe there is any way of doing this with standard C. Simply because, keyboard handling is your OS's job, and each OS will handle it differently. As for my knowledge, you will have to use the OS's API in some way, or you will have to talk directly to the keyboard, both of which will not be standard C.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by coolnerd88 View Post
    Hello I am looking for a way to do I/O event programming with keyboard (and possibly mouse) in C. I've looked for quite some time and I can't find a straightforward or consistent answer on the topic. Obviously there must be a contrived way at least of doing it. Or else how could other languages which were built on or compiled with C have I/O events? What I'm currently building/learning is to build a chat server and I want it so the user (or server) can press "escape" on the keyboard and kill their client or server. Or press another key for some other even I may put into the program. I am trying to expand my knowledge of C, Unix, networking, and event handling for other purposes. I want to see if there is any way of using standard C to do this if possible. And, as if I need to add more problems, this needs to be asynchronous. I can't have my program blocked (or at least not appear to be blocked to the user) polling all the time for keyboard press. So any help here would be hot! Thanks!

    On what Operating System? Windows? Linux? BSD? Mac? ...

    I doubt you want to do this as a console program so you will likely be using the GUI mode API calls to do your work for you.

    If you are on Windows your journey starts with theForger's Tutorial for the GUI basics then you move on to the Winsock Tutorials for the networking. Both of which provide C language examples.

    If you're on some other OS... I'm sure the others will chime in with their own FAQs and Tutorials.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Embed browser dont receives mouse "click" events
    By aniquilator in forum Windows Programming
    Replies: 2
    Last Post: 01-25-2010, 07:41 AM
  2. Replies: 46
    Last Post: 08-24-2007, 04:52 PM
  3. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  4. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM