69,382
社区成员
发帖
与我相关
我的任务
分享
#include <conio.h>
void main( void )
{
int ch;
_cputs( "input the keyword: " );
while(1)
{
ch = _getch();
if(ch==13) //回车键的ASCII码是 13
break;
_putch('*');
}
_putch( ch );
_putch( '\r' );
_putch( '\n' );
}
#include <cstdlib>
#include <cstdio>
#include <conio.h>
#include <windows.h>
#include <process.h>
HANDLE hStdOut;
bool IsOn=true;
bool IsOver=false;
void GoToXY(int x, int y) //定位光标的小函数
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
int errorIndex = GetLastError();
if(errorIndex != 0)
{
printf("\ngoto xy error:%d\n",errorIndex);
return;
}
SetConsoleCursorPosition(hOut, pos);
}
DWORD WINAPI ThreadFunc_CheckKey( LPVOID lp ) //监控键盘的线程函数
{
while(!IsOver)
{
while(1)
{
if (getch())
break;
Sleep(20);
}
if(IsOn)
SuspendThread(hStdOut);
else
ResumeThread(hStdOut);
IsOn=!IsOn;
}
return 0;
}
DWORD WINAPI ThreadFunc_run( LPVOID lp )
{
for (int i = 0;i<1000 ; ++i)
{
GoToXY(0,0);
printf("%d", i);
Sleep(10);
}
IsOver=true;
return 0;
}
void main()
{
CreateThread(NULL,0,ThreadFunc_CheckKey,NULL,0,NULL);
hStdOut=CreateThread(NULL,0,ThreadFunc_run,NULL,0,NULL);
while(!IsOver)
{
Sleep(30);
}
}
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
int main(int argc, char* argv[])
{
for (int i = 0; ; ++i)
{
if (!_kbhit())
cout << i;
else
break;
}
system("PAUSE");
return 0;
}