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

📄 keyboard.h

📁 嵌入式arm机开发的五子棋游戏
💻 H
字号:
#include <stdio.h>#include <sys/types.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include "kbd_types.h"
#define KEYBOARD "/dev/mcu/kbd"

#ifndef _KBD_H
#define _KBD_H

int  KBD_Open(void);
void KBD_Close(void);
void KBD_GetModifierInfo(MWKEYMOD *modifiers, MWKEYMOD *curmodifiers);
int  KBD_Read(char *kbuf, MWKEYMOD *modifiers, MWSCANCODE *scancode);
#endif
static int fd;typedef struct
{	unsigned short mwkey;	int scancode;}KeyMap;static unsigned short scancodes[64];#define __I2C_MEGA8__#ifdef __ZLG7289__static KeyMap keymap[] = {      {MWKEY_KP0,  0x1d},       {MWKEY_KP1,  0x21},       {MWKEY_KP2,  0x25},       {MWKEY_KP3,  0x23},       {MWKEY_KP4,  0x29},       {MWKEY_KP5,  0x2d},       {MWKEY_KP6,  0x2b},       {MWKEY_KP7,  0x31},       {MWKEY_KP8,  0x35},       {MWKEY_KP9,  0x33},       {MWKEY_NUMLOCK, 	0x11},       {MWKEY_KP_DIVIDE,	0x15},       {MWKEY_KP_MULTIPLY,	0x13},       {MWKEY_KP_MINUS,	0x0b},       {MWKEY_KP_PLUS,		0x34},       {MWKEY_KP_ENTER,	0x24},       {MWKEY_KP_DEL,	0x1b}, };#else#ifdef __I2C_MEGA8__static KeyMap keymap[] = {		//update map policy      {MWKEY_KP0,  0x0b},       {MWKEY_KP1,  0x02},       {MWKEY_KP2,  0x03},       {MWKEY_KP3,  0x04},       {MWKEY_KP4,  0x05},       {MWKEY_KP5,  0x06},       {MWKEY_KP6,  0x07},       {MWKEY_KP7,  0x08},       {MWKEY_KP8,  0x09},       {MWKEY_KP9,  0x0a},             {MWKEY_NUMLOCK, 	0x2a},       {MWKEY_KP_DIVIDE,	0x35},       {MWKEY_KP_MULTIPLY,	0x37},       {MWKEY_KP_MINUS,	0x4a},       {MWKEY_KP_PLUS,		0x4e},       {MWKEY_KP_ENTER,	0x1c},       {MWKEY_KP_DEL,	0x53}, };#endif //__I2C_MEGA8__#endif //__ZLG7289__int KBD_Open(void){	int i;		fd = open(KEYBOARD, O_RDONLY | O_NONBLOCK);	if (fd < 0) 
	{		printf("%s - Can't open keyboard!\n", __FUNCTION__);		return -1;	}	for (i=0; i<sizeof(scancodes)/sizeof(scancodes[0]); i++)		scancodes[i]=MWKEY_UNKNOWN;	for (i=0; i< sizeof(keymap)/sizeof(keymap[0]); i++)		scancodes[keymap[i].scancode]=keymap[i].mwkey;	return fd;}void KBD_Close(void){	close(fd);	fd = -1;}void KBD_GetModifierInfo(unsigned int * modifiers, unsigned int * curmodifiers){	if (modifiers)		*modifiers = 0;	/* no modifiers available */	if (curmodifiers)		*curmodifiers = 0;}int KBD_Read(char* kbuf, unsigned int * modifiers, unsigned short * scancode){	int keydown = 0;	int cc = 0;	char buf,key;	cc = read(fd, &buf, 1);	if (cc < 0) 
	{		if ((errno != EINTR) && (errno != EAGAIN)		    && (errno != EINVAL)) 
			{				perror("KBD KEY");				return (-1);			}
		else 
			{				return (0);			}	}	if (cc == 0)		return (0);	/* If the code is big than 127, then we know that */	/* we have a key down.  Figure out what we've got */	*modifiers = 0;	if (buf & 0x80)
	{		keydown = 1;	/* Key pressed but not released */	}
	else 
	{		keydown = 2;	/* key released */	}	buf &= (~0x80);	*scancode = scancodes[(int) buf];	*kbuf = *scancode ;	return keydown;	}

⌨️ 快捷键说明

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