getting ctrl-A from command line

This is a discussion on getting ctrl-A from command line within the C++ Programming forums, part of the General Programming Boards category; Hi, I was wondering if anybody knew how to get special characters such as ctrl-a from the command line in ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    getting ctrl-A from command line

    Hi,
    I was wondering if anybody knew how to get special characters such as ctrl-a from the command line in C++ as well as display them when the user presses the keys. Thanks
    Amish

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Well, what are the conventions of the command line interpreter you're using to call your program in the first place.
    You could start by telling us which OS you're on.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Sorry I misphrased my question. I should not have said command line. I am using windows primarily but the code will be ported to linux eventually. So my program prints out some questions and asks for answers and if the user inputs ctrl-a at any time, it should quit the program. So the user should see ctrl-a when he/she presses it, be able to delete it and if he presses enter, the program should recognise ctrl-a and exit. Thanks
    Amish

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Works for me on Linux
    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    {
      char  buff[100];
      while ( cin.getline(buff,sizeof buff) ) {
        if ( buff[0] == '\x01' ) {
          cout << "Bye now" << endl;
          break;
        } else {
          cout << "Normal process of line " << buff << endl;
        }
      }
      return 0;
    }
    
    $ g++ foo.cpp
    $ ./a.out
    hello world
    Normal process of line hello world
    next is ctrl-a
    Normal process of line next is ctrl-a
    ^A
    Bye now

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Thanks for the answer.
    Amish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 07-02-2007, 12:32 AM
  2. how to capture CTRL, SHIFT and ALT ?
    By goldenrock in forum C Programming
    Replies: 3
    Last Post: 11-06-2003, 12:20 AM
  3. Trapping Ctrl Alt Delete
    By emus21 in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-17-2003, 12:10 PM
  4. Recognizing ALT or Ctrl + letter
    By MethodMan in forum C Programming
    Replies: 2
    Last Post: 02-22-2003, 06:16 PM
  5. Ctrl + Alt +Delete
    By golfinguy4 in forum Windows Programming
    Replies: 4
    Last Post: 10-27-2002, 06:46 PM

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