Showing posts with label Toggle anywhere and write anything. Show all posts
Showing posts with label Toggle anywhere and write anything. Show all posts

Friday, 16 May 2014

Toggle and Go

#include<conio.h>
#include<iostream>
#include<windows.h>
using namespace std;
void gotoxy (int x,int y)
{
    COORD coord;
    coord.X = x; coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int main()
{
    char i;
    int y=0,x=0;  
    for(int i=10,j=0;i>=0,j<=10;i--,j++)
    {
    cout<<"1.)press arrow keys to move cursor and then write anything :\n";
        cout<<"2.)press \"Esc\" to exit the program :\n\n";
    cout<<"start after "<<i<<"seconds :";
    Sleep(1000);
    system("cls");
    }
     system("cls");
    while(1)
    {
    while(!kbhit());
    i=getch();
        if(i==72 )
        {
            y--;
            if(x>=0 && y>=0)
            {
            gotoxy(x,y);
        }
        if(y<0)
              y++;
           }
       
        else if(i==80)
        {
            y++;
            if(x>=0 && y>=0)
            gotoxy(x,y);
        }
        else if(i==75)
        {
            x--;
            if(x>=0 && y>=0)
            {gotoxy(x,y);
            }
if(x<0)
x+=1;
        }
   
        else if(i==77)
        {
            x++;
            if( x>=0 && y>=0)
            {
            gotoxy(x,y);
            }
            if(x>80)
            x--;
           
}

 else if((i>='a' && i<='z') ||(i>=65 && i<=90)||i==32||i==33||i==126||i==64||i==35||i==36||i==37||i==94||i==38||i==40||i==41||i==42||i==95||i==43)
        {x++;
        if(x>80)
        {x=0,y++;}
       
        else
 cout<<i;
    }
    else if(i==60||i==62||i==63||(i>=123 &&i<=126)||i==34||i==58||i==44||i==46||i==47||i==39||i==59||(i>=91&&i<=93)||i==96)
    {x++;
    if(x>80)
        {x=0,y++;}
        else
cout<<i;
    }
    else if(i==8)
    {
    x--;
    if(x<0)
    x++;
    cout<<"\b "<<"\b";
    }
     
        else if(i==27)
        break;
       
    }
    getch();
    return 0;
}