#include <stdio.h>
#include <string.h>
#include <Windows.h>
#include <unistd.h>
#include <conio.h>
#define NR(x) sizeof(x)/sizeof(x[0])
//清屏
#define ClearScreen()
system("cls");
#define TITLE "金山打字通"
enum
{
LEFT = 1 ,
RIGHT ,
BACKSPACE ,
ESC ,
Char,
};
enum KEYBOARD
{
ESC_KEY = 27,
BACKSPACE_KEY = 8 ,
LEFT_KEY = 75 ,
RIGHT_KEY = 77
};
int iindex = 0 ;
int max = 0 ;
static int count = 0 ;
char buffer[1024] = {0} ;
int Get_User_input(HANDLE hOut,char *ch) ;
void Show_string(HANDLE hOut,const char *text) ;
//窗口初始化
void HANDLE_init(HANDLE hOut);
//定义设置光标结构体变量
CONSOLE_CURSOR_INFO cci;
//定义默认的坐标位置
COORD pos = {0,0};
int main(void)
{
char *text = "WelCome to School ... Good Good Work ,Day Day Up !" ;
char ch ;
int ret ;
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE_init(hOut);
printf("n%sn",text);
Show_string(hOut,text);
while(1)
{
if(max >= strlen(text))
break ;
ret = Get_User_input(hOut,&ch) ;
if(ret == ESC)
break ;
Show_string(hOut,text);
}
//关闭窗口句柄
CloseHandle(hOut);
return 0 ;
}
//窗口初始化
void HANDLE_init(HANDLE hOut)
{
SetConsoleTitleA(TITLE);
//获取当前的句柄---设置为标准输出句柄
//获取光标信息
GetConsoleCursorInfo(hOut, &cci);
//设置光标大小
pos.X = 0 ;
pos.Y = 2 ;
cci.dwSize = 1;
//设置光标不可见 FALSE
cci.bVisible = 0;
//设置(应用)光标信息
SetConsoleCursorInfo(hOut, &cci);
}
static int __Get_User_input(HANDLE hOut,char *ch)
{
char tmp ;
int type = Char ;
//关闭回显
pos.X = 0 ;
pos.Y = 2 ;
GetConsoleCursorInfo(hOut, &cci);
cci.dwSize = 100;
cci.bVisible = 0;
SetConsoleCursorInfo(hOut, &cci);
tmp = getch() ;
switch(tmp)
{
case ESC_KEY : type = ESC ; break ;
case BACKSPACE_KEY : type = BACKSPACE ; break ;
case LEFT_KEY : type = LEFT ; break ;
case RIGHT_KEY : type = RIGHT; break ;
}
*ch = tmp ;
//打开回显
pos.X = 0 ;
pos.Y = 2 ;
GetConsoleCursorInfo(hOut, &cci);
cci.dwSize = 100;
cci.bVisible = 1;
SetConsoleCursorInfo(hOut, &cci);
return type ;
}
//获取用于输入
int Get_User_input(HANDLE hOut,char *ch)
{
int type ;
type = __Get_User_input(hOut,ch);
switch(type)
{
case Char :
if(buffer[iindex] == '