c++ menu selection with arrow keys
C++
// Menu example for tjnapster
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <cstdlib>
using namespace std;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // used for goto
COORD CursorPosition; // used for goto
void gotoXY(int,int); // function defined below if this is new to you.
int main()
{
int menu_item=0, run, x=7;
bool running = true;
gotoXY(18,5); cout << "Main Menu";
gotoXY(18,7); cout << "->";
while(running)
{
gotoXY(20,7); cout << "1) Input";
gotoXY(20,8); cout << "2) Output";
gotoXY(20,9); cout << "3) ...";
gotoXY(20,10); cout << "4) ...";
gotoXY(20,11); cout << "Quit Program";
system("pause>nul"); // the >nul bit causes it the print no message
if(GetAsyncKeyState(VK_DOWN) && x != 11) //down button pressed
{
gotoXY(18,x); cout << " ";
x++;
gotoXY(18,x); cout << "->";
menu_item++;
continue;
}
if(GetAsyncKeyState(VK_UP) && x != 7) //up button pressed
{
gotoXY(18,x); cout << " ";
x--;
gotoXY(18,x); cout << "->";
menu_item--;
continue;
}
if(GetAsyncKeyState(VK_RETURN)){ // Enter key pressed
switch(menu_item){
case 0: {
gotoXY(20,16);
cout << "You chose Input... ";
break;
}
case 1: {
gotoXY(20,16);
cout << "You chose Output... ";
break;
}
case 2: {
gotoXY(20,16);
cout << "You chose Option 3... ";
break;
}
case 3: {
gotoXY(20,16);
cout << "You chose Option 4... ";
break;
}
case 4: {
gotoXY(20,16);
cout << "The program has now terminated!!";
running = false;
}
}
}
}
gotoXY(20,21);
return 0;
}
void gotoXY(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
}
Also in C++:
- Title
- fill c++
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- how to swap string characters in c++
- Category
- C++
- Title
- gfg left view of tree
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- pause the console c++
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- pass ss tream as parameter c++
- Category
- C++
- Title
- array<string, 7> c++
- Category
- C++
- Title
- Rectangle area hackerrank solution in c++
- Category
- C++
- Title
- c++ initialization list
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- c++ unittest in ros
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- c++ for loop syntax
- Category
- C++
- Title
- char vector to string c++
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- c++ create object
- Category
- C++
- Title
- empty string c++ value
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- what is time complexity of min_element()
- Category
- C++
- Title
- double ended queue in c++ stl
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- kruskal's algorithm c++ hackerearth
- Category
- C++
- Title
- convert char to string - c++
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- passing array to function c++ pointer
- Category
- C++
- Title
- size of a matrix using vector c++
- Category
- C++
- Title
- c++ set add element
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- c++ iterate through constant list
- Category
- C++
- Title
- c++ convert int to cstring
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- array syntax in c++
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- c++ parse int
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- maximum subarray sum in c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- opperanf >> c++
- Category
- C++
- Title
- how to find the number of cycles in a graph C++
- Category
- C++
- Title
- variabili in c++
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- differentialble programming
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- how to grab all of user input c++
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- iostream library in cpp
- Category
- C++
- Title
- iterate through unordered_map c++ in reverse order
- Category
- C++
- Title
- private and public in namespace cpp
- Category
- C++
- Title
- expected initializer before 'isdigit'|
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- input a string in c++
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- tellg and seekg c++
- Category
- C++
- Title
- pointers in cpp
- Category
- C++
- Title
- pair c++
- Category
- C++
- Title
- for loop in c++ hackerrank solution
- Category
- C++
- Title
- loop through words in string c++
- Category
- C++
- Title
- tokenize string c++
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- c++ constructor
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- how to make a heap using stl in c++
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- retu7rn this c++
- Category
- C++
- Title
- fail() in c++
- Category
- C++
- Title
- bfs in C++
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- two sum problem in c++
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- memcmp in cpp
- Category
- C++
- Title
- select elements from array C++
- Category
- C++
- Title
- vprintf
- Category
- C++
- Title
- compare values within within a vector c++
- Category
- C++
- Title
- create new file c++
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- set in c++
- Category
- C++
- Title
- howt o initialize 3d vector in c++
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- file reading c++
- Category
- C++
- Title
- ue4 modular character
- Category
- C++
- Title
- c++ sort array of ints
- Category
- C++
- Title
- initialize 2d array c++
- Category
- C++
- Title
- c++ string to int
- Category
- C++