RSS

keyboard.cpp

18 Jun

#define KEY_INT 0x16
#define KEY_BACKSPACE 0x08
#define KEY_RETURN 0x0d
#define KEY_TAB 0x09
#define KEY_SPACE 0x20

#define STATE_RSHIFT 0x01
#define STATE_LSHIFT 0x02
#define STATE_CTRL 0x04
#define STATE_ALT 0x08
#define STATE_SCROLL 0x10
#define STATE_NUM 0x20
#define STATE_CAPS 0x40
#define STATE_INS 0x80

#define NULL 0
#define TRUE 1

class Keyboard
{
private:
Screen *screen;

public:
Keyboard(Screen *scr);
~Keyboard(void);

UCHAR getKey(void);
UCHAR getSpecialKey(void);
UCHAR *getString(UCHAR *str, UCHAR max);
UCHAR *getPwdString(UCHAR *pwd, UCHAR max);
UCHAR getKeyState(UCHAR key);

void hideCursor(void);
void showCursor(void);
};

Keyboard::Keyboard(Screen *scr)
{
this->screen = scr;
return;
}

Keyboard::~Keyboard(void)
{
return;
}

UCHAR Keyboard::getKey(void)
{
UCHAR key;

asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;

return key;
}

UCHAR Keyboard::getSpecialKey(void)
{
UCHAR key;

asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, ah;

return key;
}

UCHAR *Keyboard::getString(UCHAR *str, UCHAR max)
{
UCHAR key = 0;
UCHAR i, x, y;

i = 0;

while(TRUE)
{
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;

if((key == KEY_BACKSPACE) && (i > 0))
{
this->screen->getCursorPos(&y,&x);
this->screen->setCursorPos(y, –x);
this->screen->writeChar(KEY_SPACE);

*(str + i) = NULL; i–;
}

if((key >= 32) && (key <= 126) && (i screen->getCursorPos(&y,&x);
this->screen->writeChar(key);
this->screen->setCursorPos(y, ++x);

*(str + i) = key; i++;
}

if((key == KEY_TAB) && (i screen->getCursorPos(&y,&x);
this->screen->writeChar(KEY_SPACE);
this->screen->setCursorPos(y, ++x);

*(str + i) = KEY_SPACE; i++;
}

if(key == KEY_RETURN)
{
*(str + i) = NULL;
break;
}

if(i == max) *(str + i) = NULL;
}
return str;
}

UCHAR *Keyboard::getPwdString(UCHAR *pwd, UCHAR max)
{
UCHAR key, i, x, y;

key = i = 0;

while(TRUE)
{
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;

if((key == KEY_BACKSPACE) && (i > 0))
{
this->screen->getCursorPos(&y,&x);
this->screen->setCursorPos(y, –x);
this->screen->writeChar(KEY_SPACE);

*(pwd + i) = NULL; i–;
}

if((key >= 32) && (key <= 126) && (i screen->getCursorPos(&y,&x);
this->screen->writeChar(‘*’);
this->screen->setCursorPos(y,++x);

*(pwd + i) = key; i++;
}

if((key == KEY_TAB) && (i screen->getCursorPos(&y,&x);
this->screen->writeChar(‘*’);
this->screen->setCursorPos(y,++x);

*(pwd + i) = KEY_TAB; i++;
}

if(key == KEY_RETURN)
{
*(pwd + i) = NULL;
break;
}

if(i == max) *(pwd + i) = NULL;
}

return pwd;
}

UCHAR Keyboard::getKeyState(UCHAR key)
{
UCHAR state;

asm mov ah, 0x02;
asm int KEY_INT;
asm and al, key;
asm mov state, al;

return state;
}

void Keyboard::hideCursor(void)
{
asm mov ah, 0x01;
asm mov ch, 0x20;
asm mov cl, 0x00;
asm int VIDEO_INT;

return;
}

void Keyboard::showCursor(void)
{
asm mov ah, 0x01;
asm mov ch, 0x05;
asm mov cl, 0x07;
asm int VIDEO_INT;

return;
}

 
1 Comment

Posted by on June 18, 2011 in C ++, Computer

 

One response to “keyboard.cpp

  1. seyromfr45

    June 25, 2011 at 6:11 am

    Wow,Fantastic article,it’s so helpful to me,and your blog is very good,cheap jerseys,I’ve learned a lot from your blog here,Keep on going,my friend,I will keep an eye on it,One more thing,thanks for your post!.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: