Advertisement
7_2009-2012 Miscellaneous #238228

Console Keyboard Input

keyboard controlled text animation

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
#include <windows.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
     HANDLE hout= GetStdHandle(STD_OUTPUT_HANDLE);
     HANDLE hin = GetStdHandle(STD_INPUT_HANDLE); 
     INPUT_RECORD InputRecord; 
     DWORD Events;     
     COORD coord; 
     int x = 30;
     int y = 12;
               
 void erase(){
SetConsoleTextAttribute(hout,0);
cout<<"XXXXXXXXXXXXXX";
}
 void text(){
COORD coord = {x, y};
SetConsoleCursorPosition(hout, coord); 
SetConsoleTextAttribute(hout,rand()%7+9);
cout<<"Planet Source!";
}
 void movetext(){
SetConsoleMode(hin, ENABLE_PROCESSED_INPUT);  
ReadConsoleInput(hin, &InputRecord, 1, &Events); 
    if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT) 
    {
   erase();
   x++; 
   text();
}
 else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_LEFT) 
    {   
   erase();
   x--; 
   text();   
}
 else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_UP) 
    {                 
   erase();
   y--; 
   text();          
    } 
 else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_DOWN) 
    { 
   erase();
   y++; 
   text();       
    }
FlushConsoleInputBuffer(hin);                            
}
int main()
{
cout<<"press any arrow key to start use arrow keys to move text\n"
   "keep text inside window Press Ctrl+C to Exit"; 
while(1)
{
  CONSOLE_CURSOR_INFO cci;
  cci.dwSize = 25;    
  cci.bVisible = FALSE;
  SetConsoleCursorInfo(hout, &cci);
  COORD coord = {x, y}; 
  SetConsoleCursorPosition(hout, coord);
  movetext();
}
}
Original Comments (3)
Recovered from Wayback Machine