#include "keyHandler.h"
int main()
{
SetConsoleTitle("Basic setup C++ application");
cout << "Welcome to Basic setup C++ application
Press A to say a
Press B to say b
Press C to say c" << endl;
keyHandler::runKeys();
return 0;
}
#include <iostream>
#include <Windows.h>
#include <conio.h>
using namespace std;
// needs to be public so main.cpp can access it
class keyHandler {
public:
static void runKeys();
};
#include "keyHandler.h"
// you are going to want to put your main code for the functions in here
// such as if on keypress for the letter a you will want to do it like this
// if (key == 'a' || key == 'A'
// {
// // run function/code here
// }
void keyHandler::runKeys()
{
char key; // need a char (1 character) key (A, B, C ect)
while(true)
{
// you want to pause every keypress to avoid app closing
key = _getch(); // _getch() is a "pause" and is from in conio
if (key == 'a' || key == 'A'
cout << "You pressed A" << endl;
else if (key == 'b' || key == 'B'
cout << "You pressed B" << endl;
else if (key == 'c' || key == 'C'
cout << "You pressed C" << endl;
else
cout << "This button isn't supported in this application!" << endl;
}
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.