Thread: Setting up hotkeys in console apps

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    8

    Question Setting up hotkeys in console apps

    Hey everyone, new guy here;

    I've been hooked on Linux lately, and I have a project I'd like to build, but it would require creating hotkeys/keyboard shortcuts. Looking at programs like nano or calcurse, it's obvious this is possible, but I haven't been able to find any kind of tutorial or other documentation explaining how. The little bits I've found are more for desktop environments like KDE, and even those are few and far between. So any info on the subject would be awesome! Thanks in advance.

    PS: On a different note, is there some big website I'm missing? Like when developing Windows apps I can always to to MSDN for more info; does anything similar exist for Linux?

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    What do you want to do? Give us some examples.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Dec 2018
    Posts
    8
    Sure. If you type "nano /path/to/some/file.ext" you can use the arrow keys to move the cursor around, and press CTRL + X to exit. Both of these are examples of what I'm trying to do. I know how to move the cursor using ASCII escape codes, but how would I set up the arrow keys as a hotkey? Another good example is the menu in wordgrinder. All these things run in the terminal, but give users keyboard shortcuts (like CTRL + X, or Escape, or whatever) to do stuff. That is what I would like my program to do. In Win32 there is a function called RegisterHotKey for this sort of thing, but I'm not sure what that would look like on Linux.

  4. #4
    Registered User
    Join Date
    Dec 2018
    Posts
    8
    Just found a working example here:

    https://pacificsimplicity.ca/blog/ep...-press-example

    It's not exactly what I was trying to do, but I could use it to implement keyboard shortcuts; hopefully you get what I mean by hotkeys or shortcuts by now. Even simple things like input requests ending in "[y/n[:" - you don't have to press Enter, the text isn't displayed anywhere, it just detects that you pressed Y and does its thing. I found another program that uses shortcuts, "wordgrinder" - you hit Escape to go to a menu bar, then press letters to navigate the submenus. Anyway, just thought I'd put it here in case anyone else has teh same question - or in case there is a better way.

  5. #5

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When to switch from console apps??
    By jimtuv in forum C Programming
    Replies: 18
    Last Post: 06-20-2010, 11:10 PM
  2. Windows apps verses Console apps
    By nano78 in forum Windows Programming
    Replies: 8
    Last Post: 09-22-2007, 03:41 AM
  3. Back to console apps.
    By elfjuice in forum C++ Programming
    Replies: 9
    Last Post: 01-14-2004, 11:16 PM
  4. Sound in console apps
    By harry_p in forum C++ Programming
    Replies: 2
    Last Post: 07-29-2002, 10:19 PM

Tags for this Thread