PDA

View Full Version : Directional arrows



Shogun
07-31-2003, 01:08 AM
Speaking of this I never got the dirctionbuttons to work (using GCC 1-redhat linux) even though I included the ncurses libary. This funktion should do it : Keypad(stdscr,TRUE); but I can't see any differnt befour and after I used it still get "case value out of range" when I try to compile my code. (When I try to look for the dircitionbuttons being pressed).

(And I read the faq)

Shogun
07-31-2003, 01:34 AM
I made this program to play around with to learn the ncurses libary I'll post it.


#include <stdio.h>
#include <ncurses.h>

int main (void){
WINDOW * win;
char ch;
int i=1,j=1;

initscr ();
keypad (stdscr,TRUE);
hafedelay (1); */found a better way now just have to learn to fork ()*/
noecho ();

win=newwin(25,25,1,1);
wborder (win,0,0,0,0,0,0,0,0);
wmove(win,i,j);
refresh ();
wrefresh(win);

while(ch != q){
ch=getch ();
switch (ch){
case KEY_DOWN:
i--;
wmove(win,i,j);
refresh ();
wrefresh (win);
break;
case KEY_UP:
i++;
wmove(win,i,j);
refresh ();
wrefresh (win);
break:
}
}
delwin (win);
endwin();
}



this is the code which doesn't work.

(also the text editor I use doesn't for some reson let me copy past into netscape so I wrote it looking at the other code, there may be some typos.)

Shogun
07-31-2003, 10:58 AM
okey, do I need to change to q to the askii value instad? (the while loop)

Shogun
07-31-2003, 11:25 AM
okey :)

thx a ton for the help

Shogun
07-31-2003, 12:33 PM
the program still doesn't work like it should, it's suposed to move the marker when you press arrow up and down but nothing happens....

Fredd
07-31-2003, 01:04 PM
case KEY_DOWN:
i++;
...

and


case KEY_UP:
i--;


instead of:


case KEY_DOWN:
i--;
....
case KEY_UP:
i++;
...

Shogun
07-31-2003, 01:27 PM
alrady done that, no effect.

Shogun
08-01-2003, 05:32 AM
still doesn't work. and it compile fine here, that semi colon was just a typo in the posting.

and it runs, makes the window but the keys (expect q) has no effect and the hafedelay (1); was for some sort of keyboard polling (so that the program doesn't stop on the getch () ) no good way but as I comented befour I should use a fork and execlp and a pipe to do it...

Fredd
08-03-2003, 12:29 PM
works perfectly for me...



#include <stdio.h>
#include <ncurses.h>

int main (void)
{
WINDOW *win;
int ch;
int i = 1, j = 1;

initscr ();
keypad (stdscr, TRUE);

win = newwin (25, 25, 1, 1);
wborder (win, 0, 0, 0, 0, 0, 0, 0, 0);
wmove (win, i, j);
refresh ();
wrefresh (win);

while (ch != 'q')
{
ch = getch ();
switch (ch)
{
case KEY_DOWN:
i++;
wmove (win, i, j);
refresh ();
wrefresh (win);
break;
case KEY_UP:
i--;
wmove (win, i, j);
refresh ();
wrefresh (win);
break;
}
}
delwin (win);
endwin ();
return 0;
}

compiled as such: gcc -o prog prog.c -Wall -ansi -pedantic -lncurses
is it halfdelay you are after? ($man 3 halfdelay)

See the Linux FAQ for non-blocking input.

Shogun
08-04-2003, 02:38 AM
actouly it isn't, it's moving the curser I'm after.

Fredd
08-04-2003, 08:47 AM
Originally posted by Shogun
actouly it isn't, it's moving the curser I'm after.

Yeah... I was thinking halfdelay() instead of the incorrect hafedelay()...

Don't know what to tell ya... moving the cursor works just fine over here....

Shogun
08-04-2003, 09:04 AM
still doesn't work :(

(tryed to compile it adding -ansi -pedantic)

Shogun
08-04-2003, 09:11 AM
this is strange when I tryed to copy/past the code you posted and compile it it worked although it is the very same code I got..... :really confussed: