C and Cpp

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDesktop ProgrammingC and Cpp

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old December 10th, 2010, 04:05 PM
emp1953 emp1953 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Dec 2010
Posts: 1 emp1953 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 28 sec
Reputation Power: 0
C- Keyboard input - function keys

I am developing on a new Dell with the latest version of Enterprise Red Hat Linux with the latest GCC compiler. I took the following code off of another site. Upon implementing it I find that I can't decode function keys, which was my primary need.
The app I am writing needs to decode f1 thru f32 So I need the F1-F12, then shift F1-F12, and ctrl(or alt) F1-F8.

A function keypress return value from this code begins with a 27 which is an escape key press. I can adjust my app controls to get around this annoying discovery.

Additionally a shift F1 brings up some drop down menus and other shift F keys bring up other drop down menus. Seems to be related to the GNOME environment. cntrl fkey and altfkey don't provide any return values at all.

Does anyone have any suggestions on how to modify the below code to correctly decode all of the function keys that I need?

Thank you

Code:
#include <stdlib.h> 
#include <string.h> 
#include <sys/select.h> 
#include <termios.h>  

struct termios orig_termios;  

void reset_terminal_mode() {     
     tcsetattr(0, TCSANOW, &orig_termios); }  

void set_conio_terminal_mode() {     
     struct termios new_termios;      
     /* take two copies - one for now, one for later */
     tcgetattr(0, &orig_termios);
     memcpy(&new_termios, &orig_termios, sizeof(new_termios));      
     /* register cleanup handler, and set the new terminal mode */     
     atexit(reset_terminal_mode);     
     cfmakeraw(&new_termios);     
     tcsetattr(0, TCSANOW, &new_termios); }  

int kbhit() {     
     struct timeval tv = { 0L, 0L };
     fd_set fds;
     FD_SET(0, &fds);
     return select(1, &fds, NULL, NULL, &tv); }  

int getch() {
     int r;
     unsigned char c;
     if ((r = read(0, &c, sizeof(c))) < 0) {
         return r;     } 
     else {         return c;     } 
     }  

int main(int argc, char *argv[]) {
     set_conio_terminal_mode();
      while (!kbhit()) {
         /* do some work */
     }     
     (void)getch(); 
     /* consume the character */ 
} 

Reply With Quote
Reply

Viewing: Tutorialized ForumsDesktop ProgrammingC and Cpp > C- Keyboard input - function keys


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap