Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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 Engineer
    Join Date
    Jan 2005
    Saint Paul, MN
    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
    Seattle, WA, USA
    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:

  4. $spacer_open
  5. #4
    Hi friends!! thank you all very much!!!

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

        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