Find the answer to your Linux question:
Results 1 to 4 of 4
Hi Friends!! I am developing a command-line user interface in C using readline, and I have to add a function so that when the user press a shortcut, one editor ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Nov 2009
    Posts
    104

    get ctrl + key in C


    Hi Friends!!

    I am developing a command-line user interface in C using readline, and I have to add a function so that when the user press a shortcut, one editor is opened.

    The problem is that I don't know how to get a ctrl + key in C, for example ctrl + s.

    Is there anyway to get these shorcuts in C??

    Thank you very much!!

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    675
    The problem is that some of the control keys are grabbed by the pty (or tty). The control-s is grabbed to "stop/pause" output from stdout/stderr until the control-q is pressed to "resume" output. Some control keys sent signals to the process such as control-z, control-c, control-\, etc. If you are using a "GUI desktop" such as Gnome, KDE, etc, they can also grab several control keys as well.

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    You can look into "man termios", and in particular, canonical mode. This is (as I understand it) what shells do in order to support grabbing the tab character immediately, for instance. Note that this does disable any sort of line editing, unless you can configure anything with readline directly (I know nothing about readline).

    Looking into readline a bit more, you may be able to bind your key directly in readline:
    http://cnswww.cns.cwru.edu/php/chet/...ine.html#SEC32

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie
    Join Date
    Nov 2009
    Posts
    104
    Hi friends!! thank you all very much!!!

    I found the solution by myself. All I have to do is call to

    Code:
        rl_bind_key(0x05,myfunction); // ctrl+e will launch myfunction
    Which will launch myfunction when ctrl + e is pressed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •