Thread: Control and Keyboard Input

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    4

    Control and Keyboard Input

    Hello, C++ novice back again, and I now have a new question which I can't seem to find a clear answer to on the Internet.

    First of all, I'm trying to write a functional text editor, and I'm wondering how to get my program to recognize a key combination (<ctrl>+O for opening files, for example) and using that information to preform whatever function. However, the problem is, I don't know how C++ handles key combinations.

    Could somebody help me by informing me of a function that can preform key combinations? Thank you for taking your time.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The answer depends on your platform. What OS/compiler are you using?

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    4
    I'm currently developing for Windows, and I'm using Dev C++ as my compiler.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    How are you storing each line whilst you're editing the file?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    4
    Quote Originally Posted by Salem View Post
    How are you storing each line whilst you're editing the file?
    I'm mostly in the conceptual stage of development (I haven't written any actual source code yet), so I haven't worked that out. What I was wondering was whether or not there was a way to get the computer to recognize keyboard combinations.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you are using command line, then you probably will need a "read keyboard without waiting for enter", which there is a sample of in the FAQ section. It would then return CTRL-O as the value 15 (O being the 15th letter in the alphabet, and can be expressed as 'O'-64 or 'O'-('A'-1)).

    There are OTHER ways you can determine which key was pressed and what modifier keys (CTRL, SHIFT, ALT, etc) are currently active.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Will this be a console application or a windows application?

    If it's console, look at http://www.adrianxw.dk/SoftwareSite/index.html.

    If it's windows, then you have a lot more to learn than just keyboard handling. You should start with windows programming tutorials and/or books or consider learning a library like wxWidgets.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using threads for control input (keyboard, serial)
    By synthetix in forum C Programming
    Replies: 1
    Last Post: 07-06-2009, 07:43 PM
  2. Some suggestions about keyboard input ?
    By adrian2009 in forum C Programming
    Replies: 3
    Last Post: 04-19-2009, 02:36 PM
  3. Replies: 3
    Last Post: 02-29-2008, 01:29 PM
  4. Keyboard input in a Dialog
    By ksarkar in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2005, 05:39 AM
  5. I need help disabling Keyboard and Mouse input on Edit controls
    By Templario in forum Windows Programming
    Replies: 4
    Last Post: 01-07-2003, 12:59 AM