Input and Scanf

This is a discussion on Input and Scanf within the C Programming forums, part of the General Programming Boards category; Hello, my team and I are building a CL based software. We need to get input from the keyboard, such ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Input and Scanf

    Hello, my team and I are building a CL based software. We need to get input from the keyboard, such as the arrow keeps without using scanf or anything that would require the enter key and a newline.

    It would best be subscribed that I want the arrow keys to move around a cursor on screen. As of right now I am only allowed to use the windows.h library, but if it isn't possible with out something outside of windows.h, let me know.

    Thank you all.

  2. #2
    Banned
    Join Date
    Jan 2009
    Posts
    30
    You are on the right track now, DAaaMan64. You are correct in assuming you need to be messing with some platform specific API to accomplish this task. It is platform specific. Which if you think about it, is correct. The arrow keys have different scan-codes depending on OS.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    2
    Thanks for the reply. We are in windows XP exclusively. and I think we have to use gcc, but I'm not entirely sure of that.

  4. #4
    Banned
    Join Date
    Jan 2009
    Posts
    30
    You are probably going to hate me for saying this, but the easiest way I am seeing to do this task would be to write a keyboard hook that interprets keyboard events only when your console has focus.

    GetConsoleWindow() can be used after your program is created to create a global ATOM that stores the handle of your process. Or it could create any other global memory object that allows another process to communicate between your kb hook DLL and your main program. Desigh your hook DLL to have some sort of callback mechanism with any window registered to it (this is far less complicated than it really sounds). Then you can simply have the callback loop capture key events and simply use that instead of the stdio functions. The nifty thing about this method is you can still use your stdio functions without interference. As far as I can see this is the easiest way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf doesn't like order of input
    By yougene in forum C Programming
    Replies: 2
    Last Post: 12-21-2008, 12:59 PM
  2. input row of integers via scanf into an array...
    By noodles355 in forum C Programming
    Replies: 1
    Last Post: 11-20-2006, 10:12 AM
  3. reading an input line using scanf() with %c
    By linucksrox in forum C Programming
    Replies: 6
    Last Post: 04-04-2004, 04:10 PM
  4. Reading input with scanf
    By dat in forum C Programming
    Replies: 3
    Last Post: 05-29-2003, 04:54 PM
  5. Limiting scanf input
    By SMurf in forum C Programming
    Replies: 0
    Last Post: 11-21-2002, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21