... about the keyboard... well I don't know a bit of ASM (shame on me :stupid: :grin: ) and I need to get the physical state of the keyboard at one time. I could use the Windows API but I don't want to receive events when another APP simulates keypresses with keybd_event...

Luckily (or not) I found this piece of code, it may be so old that new computers might have no idea what I'm trying to do but anyways here it is:



int main(int argc, char* argv[])
{
short unsigned int keypressed;
__asm {
//pushall //**this doesn't work in C++
in al,060h // get key code
push ax // save it
in al,061h // get current control
mov ah,al // save PB control
or al,80h // set keyboard bit
out 061h,al // keyboard acknowledge
xchg ah,al // get back PB
out 061h,al // reset PB control
pop ax // get back code

mov keypressed, ax

cli
mov al,20h
out 20h,al // send eoi to interrupt controller
//popall
//iret //**this doesn't work in C++
}
printf((const char*)keypressed);
return 0;
}


Don't mind the C++ code, I don't like C++ neither but I need to make a DLL from it and it's the only way...

The problem is that the above piece of code crashes on me - GPF. I also think I should use the 32 bit registers (EAX, etc)... but as I said I'm not familiar with ASM. :rolleyes:

Thanks!
Posted on 2001-07-31 01:33:23 by AndrComm
pushall/popall ? Where exactly did you find this code? The correct
mnemonics are pushad/popad.

Using 16bit registers shouldn't really be a problem.

However, direct port access *is* a problem. We just can't have all
applications trying to get direct hardware access under a multitasking
OS... would give all sorts of problems.

And even under 16bit code, your stuff wouldn't work directly - it is
obviously meant to be set up as IRQ1, the keyboard handling IRQ.
Only IRQs should send EOI to the interrupt controller :).

As for a solution to your problem, I'm blank. I don't know if you can
achieve it without writing up a VXD/KMD (9x/NT). Why don't you want
simulated keyboard presses to work, btw?
Posted on 2001-07-31 03:19:59 by f0dder
Is there no other way beside making a VXD? The program has to run in an environment were keybd_event calls are used all the time, and I want to differentiate the virtual keypress from the physical keypress...

I guess I could make a DOS EXE that writes the keys to a file and then parse the file, but that's not very efficient...
Posted on 2001-07-31 07:05:25 by AndrComm
Dunno really. And I don't think a dos exe would help you...
Even though the dos exe THINKS it's doing direct port access, it is
really being virtualized..
Posted on 2001-07-31 07:08:16 by f0dder
Is there any way to directly access the keyboard driver? (There should be) ...how?

I don't think that virtual keypresses are sent to the driver, so this SHOULD :rolleyes: work

This is more like a general question, not necessarly ASM related...
Posted on 2001-07-31 07:52:20 by AndrComm
Ok I guess I figured that out, I have to use DeviceIOControl... I'm testing it right now...
Posted on 2001-07-31 07:55:34 by AndrComm