Last active
May 26, 2018 13:04
-
-
Save EncodeTheCode/972f404a08570f4ac3c7c6dddb3a05b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <string> | |
#include <stdio.h> | |
using namespace std; | |
char const hex[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; | |
void DisplayTitle(){cout<<"-------------------------------------\n Key press example\n Tutorial\n-------------------------------------\n\n";} | |
string v() { | |
return " pressed!\n"; | |
} | |
string s() { | |
return "\nSpace pressed!\n"; /* Trap Space key. */ | |
} | |
string a() { | |
return "\nSomething pressed...\n"; /* Trap any key besides the ones from if statement or switch. */ | |
} | |
string r() { | |
return "\nCarriage return performed!\n"; | |
} | |
string e() { | |
return "\nEnter pressed!\n"; /* Trap Enter key. 0x10, \x10 */ | |
} | |
/* | |
const char * v() { | |
return " pressed!\n"; | |
} | |
*/ | |
int main(){ | |
DisplayTitle(); | |
// Testing char: printf("%c",13); | |
cout << "Type a value... \r\n"; | |
char c; | |
c=cin.get(); | |
// else if(c=='\n') { cout << "Enter pressed!"; } | |
if(c==10) { cout<<e(); } | |
else if(c==13) { cout<<r(); } | |
else if(c==0x20) { cout<<s(); } | |
/* Mapped keys */ | |
else if(c==0x41) { cout<<"\n"<<&c<<v(); /* Trap A key. */ } | |
else if(c==0x61) { cout<<"\n"<<&c<<v(); /* Trap a key. */ } | |
else if(c==0x42) { cout<<"\n"<<&c<<v(); /* Trap B key. */ } | |
else if(c==0x62) { cout<<"\n"<<&c<<v(); /* Trap b key. */ } | |
else if(c==0x43) { cout<<"\n"<<&c<<v(); /* Trap C key. */ } | |
else if(c==0x63) { cout<<"\n"<<&c<<v(); /* Trap c key. */ } | |
else if(c==0x44) { cout<<"\n"<<&c<<v(); /* Trap D key. */ } | |
else if(c==0x64) { cout<<"\n"<<&c<<v(); /* Trap d key. */ } | |
/* Output information on key and perform conversions */ | |
else { cout<<a(); } | |
if(c!=10 || c==13) { cout << "Converted character to HEX: " << std::hex << int(c) << ".\r\nConverted character to DEC: " << std::dec << int(c) << ".\r\nConverted character to OCT: " << std::oct << int(c) << ".\r\n"; /* Convert character to encodings. */ } | |
stringstream ss; | |
string s; | |
const char * b = &c; | |
const char * d = b; | |
ss << b; | |
ss >> s; | |
cout << "Pointer: " << ss << " | Output: " << ss.str() << " | String/Char Length: " << std::char_traits<char>::length(d) << "\r\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment