GeekOS project0

直接贴代码:

keyboardfun.c

/*
 * =====================================================================================
 *
 *       Filename:  keyboardfun.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2011年10月30日 14时41分29秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Andy Lee , andyli386@gmail.com
 *        Company:  
 *		  License:  Licensed under the Academic Free License version 2.1
 *
 * =====================================================================================
 */
#define ESC ((char) 0x1B)

#include <geekos/screen.h>
#include <geekos/keyboard.h>

static void left(void);
static void right(void);
static void up(void);
static void down(void);
static void home(void);
static void end(int);
static void ascii_bs(void);
/*下面这两个函数暂时没用,一个是保存光标的位置,一个是恢复光标位置*/
static __inline__ void save(void);
static __inline__ void restore(void);

void KeyboardFunc(void)
{
	int numchar = 0;
	Keycode key;
	char	getkey;
	while(true)
	{
		key = Wait_For_Key();
		if( !(key & KEY_SPECIAL_FLAG) && !(key & KEY_KEYPAD_FLAG))	
		{
			if( key & KEY_CTRL_FLAG )
			{
				if( (key & 0xff) == 'd' )
					break;
			}
			else
			{
				getkey = key & 0xff;
				switch (getkey)
				{
					case ASCII_ESC:
						Print("ESC");
						break;
					case ASCII_BS:
						ascii_bs();
						break;
					case '\n':
						Print("%c", key);
						numchar = 0;
						break;
					default:
						Print("%c",key);
						numchar++;
				}
			}
			
		}
		else if((key & KEY_KEYPAD_FLAG) && (key & KEY_SPECIAL_FLAG)) 
		{
			switch (key) 
			{
				case KEY_KPHOME:
					home();
					break;
				case KEY_KPUP:
					up();
					break;
				case KEY_KPPGUP:
					Print("PGUP");
					break;
				case KEY_KPMINUS:
					Print("MINUS");
					break;
				case KEY_KPLEFT:
					left();
					break;
				case KEY_KPCENTER:
					Print("CENTER");
					break;
				case KEY_KPRIGHT:
					right();
					break;
				case KEY_KPPLUS:
					Print("PLUS");
					break;
				case KEY_KPEND:
					end(numchar);
					break;
				case KEY_KPDOWN:
					down();
					break;
				case KEY_KPPGDN:
					Print("PGDN");
					break;
				case KEY_KPINSERT:
					Print("INSERT");
					break;
				case KEY_KPDEL:
					Print("DEL");
					break;
			}
		}
		else if(!(key & KEY_KEYPAD_FLAG) && (key & KEY_SPECIAL_FLAG)) 
		{
			switch (key)
			{
				case KEY_UNKNOWN:
					break;
				case KEY_F1:
					Print("F1");
					break;
				case KEY_F2:
					Print("F2");
					break;
				case KEY_F3:
					Print("F3");
					break;
				case KEY_F4:
					Print("F4");
					break;
				case KEY_F5:
					Print("F5");
					break;
				case KEY_F6:
					Print("F6");
					break;
				case KEY_F7:
					Print("F7");
					break;
				case KEY_F8:
					Print("F8");
					break;
				case KEY_F9:
					Print("F9");
					break;
				case KEY_F10:
					Print("F10");
					break;
				case KEY_F11:
					Print("F11");
					break;
				case KEY_F12:
					Print("F12");
					break;
			}
		}
//		Print("This is KeyboardFunc runingI\n");
	}
	Print("\nEnd Input!\n");	
}

static void ascii_bs(void) 
{
	int row, col;
	Get_Cursor(&row, &col);
	Put_Cursor(row, col-1);
	Put_Char(ESC);
	Put_Char('[');
	Put_Char('K');
}

static void left(void) 
{
	int row, col;
	Get_Cursor(&row, &col);
	Put_Cursor(row, col-1);

}

static void right(void)
{
	int row, col;
	Get_Cursor(&row, &col);
	Put_Cursor(row, col+1);
}

static void up(void)
{
	int row, col;
	Get_Cursor(&row, &col);
	Put_Cursor(row-1, col);
}

static void down(void)
{
	int row, col;
	Get_Cursor(&row, &col);
	Put_Cursor(row+1, col);
}

static void home(void)
{
	int row, col;
	Get_Cursor(&row, &col);
	Put_Cursor(row, 0);
}

static void end(int num)
{
	int row, col;
	Get_Cursor(&row, &col);
	Put_Cursor(row, num);
}

static __inline__ void save(void)
{
	Put_Char(ESC);
	Put_Char('[');
	Put_Char('s');
}

static __inline__ void restore(void)
{
	Put_Char(ESC);
	Put_Char('[');
	Put_Char('u');
}

/*
 * =====================================================================================
 *
 *       Filename:  keyboardfun.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2011年10月30日 14时43分39秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Andy Lee , andyli386@gmail.com
 *        Company:  
 *		  License:  Licensed under the Academic Free License version 2.1
 *
 * =====================================================================================
 */
#ifndef KEYBOARDFUNC_H
#define KEYBOARDFUNC_H
void KeyboardFunc(void);

#endif


具体使用:

1、把keyboardfun.h拷到include/geekos
2、把keyboardfun.c拷到src/geekos
3、Makefile中KERNEL_C_SRCS后添加keyboardfun.c
4、在main.c中添加:#include <geekos/keyboardfun.h>
      和Start_Kernel_Thread((Thread_Start_Func)KeyboardFunc,0,PRIORITY_HIGH,true);


添加完成后需要修改keyboard.c
1、s_scanTableNoShift[] s_scanTableWithShift[]中的'\r'改成'\n'
2、注释186行
3、Enqueue_Keycode(keycode);
    改成
    if(!release)
    {
Enqueue_Keycode(keycode);
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值