Advertisement
f0rkB0mb

Huzaifa Tariq's Code

Oct 15th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. #define BLACK 0
  10. #define BLUE 1
  11. #define GREEN 2
  12. #define CYAN 3
  13. #define RED 4
  14. #define MAGENTA 5
  15. #define BROWN 6
  16. #define LIGHTGRAY 7
  17. #define DARKGRAY 8
  18. #define LIGHTBLUE 9
  19. #define LIGHTGREEN 10
  20. #define LIGHTCYAN 11
  21. #define LIGHTRED 12
  22. #define LIGHTMAGENTA 13
  23. #define YELLOW 14
  24. #define WHITE 15
  25. #define DONT_BLINK 0
  26. #define BLINK 1
  27.  
  28. void gotoxyinput(short x, short y)
  29. {
  30.     COORD pos = {x, y};
  31.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
  32. }
  33.  
  34. void gotoxyColorPrint(char cstr[], int x, int y, int color= WHITE)
  35. {
  36.     HANDLE hConsoleOutput;
  37.     COORD dwCursorPosition;
  38.     cout.flush();
  39.     dwCursorPosition.X = x;
  40.     dwCursorPosition.Y = y;
  41.     hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  42.     SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
  43.     SetConsoleTextAttribute(hConsoleOutput,color);
  44.     cout<<cstr;
  45.     SetConsoleTextAttribute(hConsoleOutput,YELLOW);
  46. }
  47.  
  48. int main()
  49. {
  50.  
  51.     //Following will put a character at the given place
  52.     //gotoxyColorPrint("",30,10,YELLOW);
  53.  
  54.     //Following will just take the cursor to the given place
  55.     //gotoxyColorPrint("", 31,10);
  56.  
  57.     int CP_x=0;
  58.     int CP_y=0;
  59.     gotoxyinput(CP_x,CP_y);
  60.  
  61.     char input;
  62.     //char input[2]={'\0','\0'};
  63.     char text[2000];
  64.     int CP=0;
  65.  
  66.     while(true)
  67.     {
  68.         input=getch();
  69.         text[CP]=input;
  70.         //gotoxyColorPrint("",CP_x,CP_y);
  71.         //gotoxyColorPrint(input,CP_x,CP_y);
  72.  
  73.         if(input>=65 && input<=90)
  74.         {
  75.             gotoxyinput(CP_x,CP_y);
  76.             text[CP]=input;
  77.             CP_x++;
  78.             CP_y++;
  79.             CP++;
  80.         }
  81.  
  82.         input=getch();
  83.  
  84.         if(input==-32)
  85.         {
  86.             //arrow key pressed
  87.             input = getch();
  88.  
  89.             if(input==72)//Up Arrow
  90.             {
  91.                 CP_y=CP_y-1;
  92.                 gotoxyinput(CP_x , CP_y);
  93.             }
  94.             else if(input==77)//Right Arrow
  95.             {
  96.                 CP_x=CP_x+1;
  97.                 gotoxyinput(CP_x , CP_y);
  98.             }
  99.             else if(input==80)//Down Arrow
  100.             {
  101.                 CP_y=CP_y+1;
  102.                 gotoxyinput(CP_x , CP_y);
  103.             }
  104.             else if(input==75)//Left Arrow
  105.             {
  106.                 CP_x=CP_x-1;
  107.                 gotoxyinput(CP_x , CP_y);
  108.             }
  109.         }
  110.  
  111.         if(input==32)//Space
  112.         {
  113.             CP_x=CP_x+1;
  114.             gotoxyinput(CP_x , CP_y);
  115.         }
  116.         else if(input==13)//Enter
  117.         {
  118.             CP_x=0;
  119.             CP_y=CP_y++;
  120.             gotoxyinput(CP_x , CP_y);
  121.         }
  122.         else if(input==8)//Backspace
  123.         {
  124.             CP_x=CP_x-1;
  125.             gotoxyinput(CP_x , CP_y);
  126.         }
  127.         else if(input==127)//Delete
  128.         {
  129.             CP_x=CP_x+1;
  130.             gotoxyinput(CP_x,CP_y);
  131.         }
  132.         else if(input==27)//Esc
  133.         {
  134.             break;
  135.         }
  136.  
  137.     }
  138.  
  139.     cin.get();
  140.     getch();
  141.     return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement