Directional arrows

This is a discussion on Directional arrows within the Linux Programming forums, part of the Platform Specific Boards category; Speaking of this I never got the dirctionbuttons to work (using GCC 1-redhat linux) even though I included the ncurses ...

  1. #1
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259

    Speaking of this....

    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)
    Last edited by Shogun; 07-31-2003 at 02:11 AM.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  2. #2
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    I made this program to play around with to learn the ncurses libary I'll post it.
    Code:
    #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.)
    Last edited by Shogun; 07-31-2003 at 02:40 AM.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  3. #3
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    okey, do I need to change to q to the askii value instad? (the while loop)
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  4. #4
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    okey

    thx a ton for the help
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  5. #5
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    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....
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  6. #6
    Registered User Fredd's Avatar
    Join Date
    Oct 2002
    Posts
    69
    Code:
    case KEY_DOWN:
         i++;
    ...
    and
    Code:
    case KEY_UP:
         i--;
    instead of:

    Code:
    case KEY_DOWN:
         i--;
    ....
    case KEY_UP:
         i++;
    ...
    "Writing software is more fun than working."

    got slack?
    http://www.slackware.com/

  7. #7
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    alrady done that, no effect.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  8. #8
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    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...
    Last edited by Shogun; 08-01-2003 at 06:37 AM.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  9. #9
    Registered User Fredd's Avatar
    Join Date
    Oct 2002
    Posts
    69
    works perfectly for me...

    Code:
    #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.
    "Writing software is more fun than working."

    got slack?
    http://www.slackware.com/

  10. #10
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    actouly it isn't, it's moving the curser I'm after.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  11. #11
    Registered User Fredd's Avatar
    Join Date
    Oct 2002
    Posts
    69
    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....
    "Writing software is more fun than working."

    got slack?
    http://www.slackware.com/

  12. #12
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    still doesn't work

    (tryed to compile it adding -ansi -pedantic)
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  13. #13
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    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:
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Directional arrows
    By Ian Paice in forum C Programming
    Replies: 4
    Last Post: 07-31-2003, 08:57 AM
  2. directional keys @ console
    By ipe in forum C Programming
    Replies: 1
    Last Post: 03-13-2003, 06:25 AM
  3. up, down, left, right arrows
    By revelation437 in forum C Programming
    Replies: 10
    Last Post: 12-12-2002, 09:38 AM
  4. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM
  5. Using Arrows in Win32 Console
    By GreenCherry in forum C++ Programming
    Replies: 2
    Last Post: 10-04-2002, 12:27 PM

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