⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keys.h

📁 FritzOS - 简单的C++开发OS的实例// 英文
💻 H
字号:
/* keys.h : FritzOS Key Board I/O Header File For The FritzOS C++ Kernel   Copyright (C) 2002 Tom Fritz * This program is a part of the FritzOS kernel, and may be freely * copied under the terms of the GNU General Public License (GPL), * version 2, or at your option any later version.   For more info, look at the COPYING file.*/// defines:#ifndef KEYS_H#define KEYS_H// Check to see if types.h is not included - keys.h needs it#ifndef TYPES_H#error keys.h needs types.h		// ERROR, file not included.#endif// Check to see if x86.h is not included - keys.h needs it#ifndef X86_H#error keys.h needs x86.h		// ERROR, file not included.#endif// If someone likes using lower-case functions, define GetRawKey to getrawkey, and others#define getrawkey GetRawKey#define getrawkeynow GetRawKeyNow// Includes:#include "keydefs.h"		// Keyboard defines// voids:// For getting keys from the keyboard.UCHAR const getch();// For getting raw keyboard scancodesUINT GetRawKey();// For getting raw keyboard scancodes without waiting for a key.UINT GetRawKeyNow();// data:// For keeping track if the shift key is down or upint shift;// Create a typedef for getting keys, to hold the correct value:typedef UCHAR KEY;// Create a raw scancode data type for getting scancodes:typedef UINT RAWKEY;// It converts scancode to ASCII, too...// Example:// KEY KeyGot = getch();KEY const getch(){	RAWKEY scan;			// For holding the scancode from the keyboard	KEY retchar;			// The chararacter that returns the Scancode to ASCII code	// Get the scancode	scan = getrawkey();	// Check to see if the shift key is down	if ( shift ) 				// same as if ( shift == TRUE )		retchar = asciiShift[ scan ];	// It is, use the upper shift codes	// Not down	else if ( !shift )			// same as else if ( shift == FALSE )		retchar = asciiNonSh[ scan ];	// Not down - use lower shift codes	// Return the ASCII version of the scancode...i.e the converted code	return retchar;				}//************************************************************************************************************//// Example: int thekey = getrawkey(); 		// you can also use getrawkey instead of GetRawKeyUINT GetRawKey(){	RAWKEY scancode;				// For getting the keyboard raw scancode	// Loop untill a key to be pressed	while ( TRUE )	{		// Wait for the key, need this.		while ( ( inportb( 0x64 ) & 1 ) == FALSE ) // 0x64 is for reading the 8042 status register			;		scancode = getrawkeynow();		// KEYPORT is the keyboard port for getting keys		// Check to see if a key is up		if ( scancode & KEYPRESS )		{			// Key is up, need to do this:			scancode &= 0x7F;			// A key is up, check to see if the shift key is up			if ( scancode == KRLEFT_SHIFT || scancode == KRRIGHT_SHIFT )				shift = FALSE;		// it's up - don't use shifted characters			continue;			// Loop again		}		// Check to see if the shift key is down		if ( scancode == KRLEFT_SHIFT || scancode == KRRIGHT_SHIFT )		{			shift = TRUE;				// It is down, use upper shift characters.			continue;				// Restart, so it doesn't return a shift		}		// Return the key.		return scancode;	}}//************************************************************************************************************//// Example: int thekey = GetRawKeyNow();		// could also use getrawkeynow.UINT GetRawKeyNow(){	int rawkey;	// For getting the raw scancode	rawkey = inportb( KEYPORT );		// KEYPORT is 0x60 - the keyboard's keys port	// Return the keyboard scancode value:	return rawkey;}#endif// End of keys.h

⌨️ 快捷键说明

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