Menu

keyboard functions

2002-12-08
2012-09-26
  • Nobody/Anonymous

    Is there anyway to reserve keybaord functions in C++?? as in...Press 1 to do....press 2 to do...etc. Thanks

     
    • Curtis Sutter

      Curtis Sutter - 2002-12-08

      Like a menu?  Please be more precise.

      Curtis

       
      • Nobody/Anonymous

        Yes....just like a menu

         
    • Nobody/Anonymous

      This is something i offer if this is what your looking for. Please it is not the best, it is for demo.

      The program has 3 calls to functions. Here the functions only print a message to screen. But, using the switch statement you can do a 'reserve keybaord functions '...

      If you have any questions, please do return to this thread to ask them... Thank you.
      j@ck_

      #include <iostream>
      #include <cstdlib>

           using namespace std;
          
          
      void saldot();  // Function ( all 3 ) prototypes
      void mosdot();
      void dordot();   

      int main( )
        {
       
        enum system {     // ....... starts enum
          WState_A = 1,
          WState_B,
          WState_C,
          quit
      };  // ....................... ends enum

      int system = 0 ;             // Variable

      do {
      cout << "Enter function number ( 1 - 3 )  (4)to exit: " ;
      cin >> system;               // enter value

      switch(system) // ............ start switch
      {
      case WState_A: // ..... Checks for first value
         saldot(); // ... calls the function
        break; // If value one then ends here
      case WState_B: // ..... Checks for second value
         mosdot(); // ... calls the function
        break; // If value two then ends here
      case WState_C: // ..... Checks for thrid value
         dordot(); // ... calls the function
        break; // If value three then ends here

      default: // If not any of the above then this massage will print to screen.
        cout << "The Number  "<< system << " Is not a Function. \n" ;
      break;
      } // ........................ end switch

         }while(system != 4);
          return 0;
        }             // ends main()
       

        
      void saldot()                                        // Function definition
      {
        cout <<"You called saldot Function...\n"; 
        }
       
      void mosdot()                                        // Function definition
      {
        cout <<"You called mosdot Function...\n";
        }
       
      void dordot()                                        // Function definition 
      {
        cout <<"You called dordot Function...\n";
        }  

       
    • Curtis Sutter

      Curtis Sutter - 2002-12-08

      Although a little more advanced than nessairy, J@ck's solution should work.
      I have a menu I created once that is very versitile if you would like to try it.

      Curtis

       
    • Nobody/Anonymous

      Sure Curtis, that would be appreciated, just learning C++, and any ideas that I can see and try out is a good thing.

      Thanks

       
    • Curtis Sutter

      Curtis Sutter - 2002-12-09

      I have some changes to make to it, and I will write a test program for it.  Then I will post a link one the "Programs" thread.

      Curtis

       
    • Curtis Sutter

      Curtis Sutter - 2002-12-09
       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.