nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

curses Problems with Non-Blocking input

This is a discussion on curses Problems with Non-Blocking input within the Coding in General forums, part of the Development/Scripting category; Hi all, I'm trying to get a simple curses program working on Solaris using gcc. it compile and everything about ...


Go Back   nixCraft Linux Forum > Development/Scripting > Coding in General

Linux answers from nixCraft.


Coding in General Discussion on PHP/Perl/Python/Ruby/GNU C or C++. MySQL, PgSQL and (X)HTML or any other programming languages you want.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 27-03-2005, 11:08 PM
Junior Member
User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
kgmf
Default curses Problems with Non-Blocking input

Hi all,
I'm trying to get a simple curses program working on Solaris using gcc.
it compile and everything about the code is just fine appart from the part where it reads input. Its the begginings of a game (but its just nonsense at the moment, I'm just trying to get a basic input/display loop going)

There are supposedly ways to make getchar() non-blocking. I found refference to them here:
http://www.gsp.com/cgi-bin/man.cgi?s...opic=halfdelay

I've tried them all to no avail. The proram fails to progress unless the user hits a key.

Basically if it worked the way I wanted "moo" would shoot off the end of the screen instantly, and the ship would move around with keypresses. But, "moo" only moves each time the key is pressed. And I know there's no function call to make getchar() non-blocking in there at the moment, but i tried them all on the previous link (the gsp one) and none worked. Any ideas?


The code is as follows:
#include <curses.h>
#include <string.h>
#define XMAX 95
#define YMAX 76
#define XMIN 0
#define YMIN 2
void update_ship();
void update_thing();
int level = 1;
int lives = 30;
int ship_y = 58;
int ship_x = 20;
char ship1[]=" .^. ";
char ship2[]="-<_>-";

int main(){
initscr(); /* Start curses mode */
noecho(); /* Don't echo() while we do getch */
keypad(stdscr, TRUE);

mvprintw(level,10,"moo");
while(lives > 0){
timeout(10);
int ch = getchar();
if (ch == 'a'){
ship_x--;
}

else if (ch == 'd'){
ship_x++;
}
else if (ch == 'q'){
lives = -1;
}
else if (ch == ' '){
//fire somehow
}

else if (ch == 'w'){
ship_y--;
}

else if (ch == 's'){
ship_y++;
}

initscr();//clear screen

//redraw screen
update_ship();
update_thing();
}
endwin(); /* End curses mode */
printf("\n\nyou died you twat\n");
return 0;
}
void update_ship(){

mvprintw(ship_y, ship_x, ship1);
mvprintw(ship_y+1, ship_x, ship2);
mvprintw(0, 0, " ");
refresh();
}

void update_thing(){
mvprintw(level,10,"moo");
level++;
refresh();
}
Reply With Quote
  #2 (permalink)  
Old 28-03-2005, 12:12 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,706
Thanks: 11
Thanked 243 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Have you tryied the getch or wgetch? They may solve your problem

let me know...
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 28-03-2005, 11:24 PM
Junior Member
User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
kgmf
Default Well I'm an idiot

*sheepishly*


it works!
thanks!
Reply With Quote
  #4 (permalink)  
Old 01-04-2005, 01:49 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
OS: Debian GNU/Linux
Posts: 506
Thanks: 0
Thanked 8 Times in 6 Posts
Rep Power: 7
monk has a spectacular aura about monk has a spectacular aura about
Default Re: Well I'm an idiot

Quote:
Originally Posted by kgmf
*sheepishly*
Forum is for help so don't get sheepishly
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Interpreting ~ from user input al001 Shell scripting 2 21-04-2008 08:27 PM
blocking streaming zafar466 CentOS / RHEL / Fedora 0 12-04-2008 03:37 AM
Shell script to supply or input a password passphrase kasimani Shell scripting 1 21-02-2007 09:21 AM
iptables rules blocking ftp hammooda Linux software 7 23-09-2006 04:24 PM
Program gets aborted on large input Ssk Linux software 7 14-03-2005 11:04 AM


All times are GMT +5.5. The time now is 04:49 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38