nixCraft Linux Forum

nixCraft

Linux 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

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 03-28-2005, 12:08 AM
Junior Member
 
Join Date: Mar 2005
Posts: 2
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
Sponsored Links
  #2 (permalink)  
Old 03-28-2005, 01:12 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,060
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 | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 03-29-2005, 12:24 AM
Junior Member
 
Join Date: Mar 2005
Posts: 2
Rep Power: 0
kgmf
Default Well I'm an idiot

*sheepishly*


it works!
thanks!
Reply With Quote
  #4 (permalink)  
Old 04-01-2005, 02:49 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
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

Bookmarks


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 On

Similar Threads

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


All times are GMT +5.5. The time now is 03:12 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

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