Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <stdlib.h>
- #include <conio.h>
- #include <windows.h>
- using namespace std;
- #define BLACK 0
- #define BLUE 1
- #define GREEN 2
- #define CYAN 3
- #define RED 4
- #define MAGENTA 5
- #define BROWN 6
- #define LIGHTGRAY 7
- #define DARKGRAY 8
- #define LIGHTBLUE 9
- #define LIGHTGREEN 10
- #define LIGHTCYAN 11
- #define LIGHTRED 12
- #define LIGHTMAGENTA 13
- #define YELLOW 14
- #define WHITE 15
- #define DONT_BLINK 0
- #define BLINK 1
- void gotoxyinput(short x, short y)
- {
- COORD pos = {x, y};
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
- }
- void gotoxyColorPrint(char cstr[], int x, int y, int color= WHITE)
- {
- HANDLE hConsoleOutput;
- COORD dwCursorPosition;
- cout.flush();
- dwCursorPosition.X = x;
- dwCursorPosition.Y = y;
- hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
- SetConsoleTextAttribute(hConsoleOutput,color);
- cout<<cstr;
- SetConsoleTextAttribute(hConsoleOutput,YELLOW);
- }
- int main()
- {
- //Following will put a character at the given place
- //gotoxyColorPrint("",30,10,YELLOW);
- //Following will just take the cursor to the given place
- //gotoxyColorPrint("", 31,10);
- int CP_x=0;
- int CP_y=0;
- gotoxyinput(CP_x,CP_y);
- char input;
- //char input[2]={'\0','\0'};
- char text[2000];
- int CP=0;
- while(true)
- {
- input=getch();
- text[CP]=input;
- //gotoxyColorPrint("",CP_x,CP_y);
- //gotoxyColorPrint(input,CP_x,CP_y);
- if(input>=65 && input<=90)
- {
- gotoxyinput(CP_x,CP_y);
- text[CP]=input;
- CP_x++;
- CP_y++;
- CP++;
- }
- input=getch();
- if(input==-32)
- {
- //arrow key pressed
- input = getch();
- if(input==72)//Up Arrow
- {
- CP_y=CP_y-1;
- gotoxyinput(CP_x , CP_y);
- }
- else if(input==77)//Right Arrow
- {
- CP_x=CP_x+1;
- gotoxyinput(CP_x , CP_y);
- }
- else if(input==80)//Down Arrow
- {
- CP_y=CP_y+1;
- gotoxyinput(CP_x , CP_y);
- }
- else if(input==75)//Left Arrow
- {
- CP_x=CP_x-1;
- gotoxyinput(CP_x , CP_y);
- }
- }
- if(input==32)//Space
- {
- CP_x=CP_x+1;
- gotoxyinput(CP_x , CP_y);
- }
- else if(input==13)//Enter
- {
- CP_x=0;
- CP_y=CP_y++;
- gotoxyinput(CP_x , CP_y);
- }
- else if(input==8)//Backspace
- {
- CP_x=CP_x-1;
- gotoxyinput(CP_x , CP_y);
- }
- else if(input==127)//Delete
- {
- CP_x=CP_x+1;
- gotoxyinput(CP_x,CP_y);
- }
- else if(input==27)//Esc
- {
- break;
- }
- }
- cin.get();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement