Last active
August 8, 2018 02:10
-
-
Save jfmherokiller/288b95479593ea0e25f3c866b537d718 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
// ArrowKeyStringConstruction.cpp : Defines the entry point for the console application. | |
// | |
//#pragma warning(disable : 4996) | |
// System headers | |
#include <switch.h> | |
//#include <conio.h> | |
#include <stdio.h> | |
#include <strings.h> | |
//#include <iostream.h> | |
//Input Setup | |
int AlphaIndex = 0; | |
int InputArrayIndex = 0; | |
const char *alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz(){}[]'`^,~*?!@#$%&0123456789=+-_."; | |
char InputArray[256]; | |
#define SizeOfAlphabet 87 | |
#define ESC "\x1b" | |
#define CSI "\x1b[" | |
#define CLEARLINE CSI "2k" | |
#define MoveCursorLeftMargin CSI "280D" | |
void CharaterOperation() { | |
char NextChar = alphabet[AlphaIndex % SizeOfAlphabet]; | |
InputArray[InputArrayIndex % 256] = NextChar; | |
printf("%c%c", '\b', NextChar); // key left | |
} | |
void MoveForwardAlphabetAndPrint() { | |
AlphaIndex++; | |
CharaterOperation(); | |
} | |
void MoveBackwardAlphabetAndPrint() { | |
AlphaIndex--; | |
if (AlphaIndex < 0) { | |
AlphaIndex = 0; | |
} | |
CharaterOperation(); | |
} | |
void ResetCursor() { | |
printf(CLEARLINE); | |
printf(MoveCursorLeftMargin); | |
} | |
void MoveForwardInputBuffer() { | |
ResetCursor(); | |
InputArrayIndex++; | |
char InputIndexStr[15]; | |
char OutputStr[80]; | |
sprintf(InputIndexStr, "%d", InputArrayIndex % 256); | |
ResetCursor(); | |
printf("%s", InputArray); | |
sprintf(OutputStr, "%s%s%c", CSI, InputIndexStr, 'C'); | |
printf("%s", OutputStr); | |
} | |
void MoveBackwardInputBuffer() { | |
ResetCursor(); | |
InputArrayIndex--; | |
char InputIndexStr[15]; | |
sprintf(InputIndexStr, "%d", InputArrayIndex % 256); | |
ResetCursor(); | |
printf("%s", InputArray); | |
printf("%s%s%c", CSI, InputIndexStr, 'C'); | |
InputArrayIndex--; | |
} | |
void PrintInputBuffer() { | |
printf("%s\n", InputArray); | |
bzero(&InputArray, 256); | |
} | |
int main(int argc, char **argv) { | |
gfxInitDefault(); | |
consoleInit(NULL); | |
printf("bapis\n"); | |
while (appletMainLoop()) { | |
hidScanInput(); | |
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); | |
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu | |
if (kDown & KEY_DDOWN) { MoveBackwardAlphabetAndPrint(); } | |
if (kDown & KEY_DUP) { MoveForwardAlphabetAndPrint(); } | |
if (kDown & KEY_DLEFT) { MoveBackwardInputBuffer(); } | |
if (kDown & KEY_DRIGHT) { MoveForwardInputBuffer(); } | |
if (kDown & KEY_A) { PrintInputBuffer(); } | |
svcSleepThread(1000); | |
gfxFlushBuffers(); | |
gfxSwapBuffers(); | |
gfxWaitForVsync(); | |
} | |
gfxExit(); | |
return 0; | |
} |
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
// ArrowKeyStringConstruction.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
#pragma warning(disable : 4996) | |
// System headers | |
#include <windows.h> | |
#include <conio.h> | |
#include <stdio.h> | |
//#include <iostream.h> | |
#define KEY_UP 72 | |
#define KEY_DOWN 80 | |
#define KEY_LEFT 75 | |
#define KEY_RIGHT 77 | |
#define KEY_A 97 | |
int EnableVTMode() | |
{ | |
// Set output mode to handle virtual terminal sequences | |
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); | |
if (hOut == INVALID_HANDLE_VALUE) | |
{ | |
return FALSE; | |
} | |
DWORD dwMode = 0; | |
if (!GetConsoleMode(hOut, &dwMode)) | |
{ | |
return FALSE; | |
} | |
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | |
if (!SetConsoleMode(hOut, dwMode)) | |
{ | |
return FALSE; | |
} | |
return TRUE; | |
} | |
//Input Setup | |
int AlphaIndex = 0; | |
int InputArrayIndex = 0; | |
const char* alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz(){}[]'`^,~*?!@#$%&0123456789=+-_."; | |
char InputArray[256]; | |
#define SizeOfAlphabet 87 | |
#define ESC "\x1b" | |
#define CSI "\x1b[" | |
#define CLEARLINE CSI "2k" | |
#define MoveCursorLeftMargin CSI "280D" | |
void CharaterOperation() { | |
char NextChar = alphabet[AlphaIndex % SizeOfAlphabet]; | |
InputArray[InputArrayIndex % 256] = NextChar; | |
printf("%c%c",'\b', NextChar); // key left | |
} | |
void MoveForwardAlphabetAndPrint() { | |
AlphaIndex++; | |
CharaterOperation(); | |
} | |
void MoveBackwardAlphabetAndPrint() { | |
AlphaIndex--; | |
if (AlphaIndex < 0) | |
{ | |
AlphaIndex = 0; | |
} | |
CharaterOperation(); | |
} | |
void ResetCursor() { | |
printf(CLEARLINE); | |
printf(MoveCursorLeftMargin); | |
} | |
void MoveForwardInputBuffer() { | |
ResetCursor(); | |
InputArrayIndex++; | |
char InputIndexStr[15]; | |
char OutputStr[80]; | |
sprintf(InputIndexStr, "%d", InputArrayIndex % 256); | |
ResetCursor(); | |
printf("%s", InputArray); | |
sprintf(OutputStr,"%s%s%c", CSI, InputIndexStr, 'C'); | |
printf("%s", OutputStr); | |
} | |
void MoveBackwardInputBuffer() { | |
ResetCursor(); | |
InputArrayIndex--; | |
char InputIndexStr[15]; | |
sprintf(InputIndexStr, "%d", InputArrayIndex % 256); | |
ResetCursor(); | |
printf("%s", InputArray); | |
printf("%s%s%c", CSI, InputIndexStr, 'C'); | |
InputArrayIndex--; | |
} | |
void PrintInputBuffer() { | |
printf("%s\n", InputArray); | |
bzero(&InputArray, 256); | |
} | |
int main() | |
{ | |
EnableVTMode(); | |
int c = 0; | |
while (1) | |
{ | |
c = 0; | |
switch ((c = _getch())) { | |
case KEY_UP: | |
MoveForwardAlphabetAndPrint(); | |
break; | |
case KEY_DOWN: | |
MoveBackwardAlphabetAndPrint(); | |
break; | |
case KEY_LEFT: | |
MoveBackwardInputBuffer(); | |
break; | |
case KEY_RIGHT: | |
MoveForwardInputBuffer(); | |
break; | |
case KEY_A: | |
printf("") | |
break; | |
default: | |
//cout << endl << "null" << endl; // not arrow | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment