我正在学习这篇教程:
http://wiki.osdev.org/Keyboard
Bones
我正在尝试增加键盘支持,但是如果我按一个字符(例如'A' ),程序会一直显示数千个'A',直到我按下另一个键--例如‘1’(它也会显示数千个'1',直到我按下另一个键,等等)。我想一个一个地放置字符,我的意思是,如果'A'一旦显示一次就按下,它仍然允许我添加另一个字符。
//Places single char onto the screen
void term_putc(char c);
//Provides the scancode from kb controller
char getScancode(){
char c=0;
do {
if(inb(0x60) != c)
{
c=inb(0x60);
if(c>0)
return c;
}
}while(1);}
//transfroms scancodes to chars
char getchar();
//shows the character on the screen
void kb_print(){
char chara = getchar(); // Pressed key value
term_putc(chara);
}现在我在呼唤主要功能
void kernel_main(){
term_init();
while(1){
kb_print();
}
}整个代码:
https://pastebin.com/CMNvZN3P谢谢你的回答!
发布于 2017-10-08 18:34:14
我想我找到了第二好的解决方案。我使用了这个功能:
// Sends a 8/16/32-bit value on a I/O location
static inline void outb(uint16_t port, uint8_t val){
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );安放
outb(0x60, 0x0); 在……里面
char getScancode(){
char c=0;
outb(0x60, 0x0);
do{
if(inb(0x60) != c){
c=inb(0x60);
if(c>0)
return c;
}
}while(1);
}由于某些原因,端口0x60在按键后不为空。(如果应该的话)
https://stackoverflow.com/questions/46608895
复制相似问题