keyscan.cpp

来自「学生成绩管理系统。实现学生的添加 删除和各科成绩管理。」· C++ 代码 · 共 74 行

CPP
74
字号
#include <conio.h>
#include <ctype.h>
#include <stdarg.h>

#ifndef NULL
	#ifdef __cplusplus
		#define NULL 0
	#else
		#define NULL ((void *)0)
	#endif
#endif

int scankey(bool allowalpha, bool allowdigit, int* const extrakeys, int extracount)
{
	int ch,i;
	bool alpha, digit;
	while (1)
	{
		ch=getch();
		if (ch==0 || ch==224) ch=getch()+256;

		if (extrakeys!=NULL)
		{
			for (i=0; i<extracount; ++i)
			{
				if (ch==extrakeys[i]) return tolower(ch);
			}
		}

		alpha=isalpha(ch)!=0;
		if ( !allowalpha && alpha ) continue;
		digit=isdigit(ch)!=0;
		if ( !allowdigit && digit ) continue;

		if (!(alpha || digit)) continue;

		return tolower(ch);
	}
}

int scankey(bool allowalpha, bool allowdigit, int spe, ...)
{
	bool alpha, digit;
	int ch,i;
	va_list maker;
	while (1)
	{
		ch=getch();
		if (ch==0 || ch==224) ch=getch()+256;

		i=spe;
		va_start(maker,spe);
		while (i!=0)
		{
			if (ch==i)
			{
				va_end(maker);
				return tolower(ch);
			}
			i=va_arg(maker,int);
		}
		va_end(maker);

		alpha=isalpha(ch)!=0;
		if ( !allowalpha && alpha ) continue;
		digit=isdigit(ch)!=0;
		if ( !allowdigit && digit ) continue;

		if (!(alpha || digit)) continue;

		return tolower(ch);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?