C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-10-2006, 07:58 PM   #1
Registered User
 
divineleft's Avatar
 
Join Date: Jul 2006
Posts: 158
Function keys and strange results

Hello.

I'm writing a small game for fun and I'm having a problem with the function keys, specifically F1-F4.

Code:
#include <curses.h>

void input()
{
    int choice;
    choice = getch();
    printw("%c\n", choice);
    refresh();
}
When I press any other function key, the character returns as "^Q" or "^R", but for some reason those 4 keys (F1-F4) return things like "^[[11~". Even when I do something like:

Code:
if(choice == KEY_F(1))     // or F2,F3,F3
{
    ...
}
it doesn't work. But, If I use any of the other function keys, it works. Is this a hardware problem on my side, or am I just doing something wrong? It's not just for ncurses either, it happens regardless.

I'm on linux, if that's of any help.

Last edited by divineleft; 11-10-2006 at 08:26 PM.
divineleft is offline   Reply With Quote
Old 11-11-2006, 02:24 AM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,680
Can you post a short and complete ncurses program which prints your function keys?

Your F1 to F4 keys are generating ANSI Escape sequences, which is something they can be programmed to do in various kinds of terminal emulation modes. How you change that depends on what you're using.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 11-11-2006, 06:33 AM   #3
Registered User
 
divineleft's Avatar
 
Join Date: Jul 2006
Posts: 158
Sure.

Code:
#include <curses.h>
#include <iostream>


void menu();

int main()
{
	initscr();
	keypad(stdscr, TRUE);
	noecho();
	scrollok(stdscr, TRUE);
	
	menu();
	
	endwin();
	return 0;
}

void menu()
{
    int choice;
    while (choice = getch())
    {
    	printw("%c\n", choice);
    	refresh();
    }
}
divineleft is offline   Reply With Quote
Old 11-12-2006, 06:39 AM   #4
.
 
Join Date: Nov 2003
Posts: 293
ncurses returns an integer - some keys like F1 send 265, if I remember, by default in ncurses. Which is beyond the limits for unsigned char. getch() returns an integer.
jim mcnamara is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ToUnicodeEx and dead keys inside system wide hooks RevengerPT Windows Programming 1 08-13-2009 02:51 PM
Strange Keyboard MadCow257 Tech Board 5 05-12-2005 10:54 PM
Strange Direct Input Behaviour Diamonds Windows Programming 2 06-23-2003 04:34 PM


All times are GMT -6. The time now is 06:04 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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