Pages vues depuis 25/07/2007 : 25 173 804
Index du forum »» Création-Développement »» Aide pour Keyboard.device
Mon source est exactement le même que le Read_Keyboard_Matrix.c qui est ici
http://wiki.amigaos.net/wiki/Keyboard_Device
Je rajoute juste une var
ULONG x;
et modifie la partie centrale juste ainsi
for(x=0;x<100;x++)
{
IExec->DoIO ( ( struct IORequest *) KeyIO );
/* Check for CLI startup... */
if ( argc )
{
Display_Matrix( keyMatrix );
}
}
Pour avoir l'occasion de taper une touche avant que le prog finisse
Alain
Note: ce prog doit être lancé depuis le shell/cli
gcc -noixemul -c keyboard.c
gcc -noixemul -o keyboard keyboard.o
/*
* Read_Keyboard_Matrix.c
*
* Compile with gcc (GCC) 4.2.4
* gcc -o Read_Keyboard_Matrix Read_Keyboard_Matrix.c
*
* Run from CLI only
*/
#include <proto/exec.h>
#include <proto/dos.h>
#include <devices/keyboard.h>
/*
* There are keycodes from 0x00 to 0x7F, so the matrix needs to be
* of 0x80 bits in size, or 0x80/8 which is 0x10 or 16 bytes...
*/
#define MATRIX_SIZE 16L
/*
* This assembles the matrix for display that translates directly
* to the RAW key value of the key that is up or down
*/
void Display_Matrix ( uint8 *keyMatrix )
{
int16 bitcount;
int16 bytecount;
int16 mask;
uint16 twobyte;
IDOS->Printf( "\n 0 1 2 3 4 5 6 7" );
IDOS->Printf( "\n +-----------------" );
for ( bitcount = 0; bitcount < 16; bitcount++ )
{
IDOS->Printf( "\n%lx |", bitcount );
mask = ( 1 << bitcount );
for ( bytecount = 0; bytecount < 16; bytecount += 2 )
{
twobyte = keyMatrix [ bytecount ] | ( keyMatrix [ bytecount + 1 ] << 8 );
if ( twobyte & mask )
{
IDOS->Printf( " *" );
}
else
{
IDOS->Printf( " -" );
}
}
}
IDOS->Printf( "\n\n" );
}
int main ( int argc, char *argv[] )
{
struct IOStdReq *KeyIO;
struct MsgPort *KeyMP;
uint8 *keyMatrix;
ULONG x;
if ( KeyMP = IExec->AllocSysObjectTags ( ASOT_PORT, TAG_END ) )
{
if ( KeyIO = IExec->AllocSysObjectTags ( ASOT_IOREQUEST, ASOIOR_ReplyPort, KeyMP, ASOIOR_Size, sizeof ( struct IOStdReq ), TAG_END ) )
{
if ( ! IExec->OpenDevice ( "keyboard.device", 0, ( struct IORequest * ) KeyIO, 0 ) )
{
if ( keyMatrix = IExec->AllocVecTags ( MATRIX_SIZE, AVT_ClearWithValue, 0, TAG_END ) )
{
KeyIO->io_Command = KBD_READMATRIX;
KeyIO->io_Data = ( APTR ) keyMatrix;
KeyIO->io_Length = MATRIX_SIZE;
for(x=0;x<100;x++)
{
IExec->DoIO ( ( struct IORequest *) KeyIO );
/* Check for CLI startup... */
if ( argc )
{
Display_Matrix( keyMatrix );
}
}
IExec->FreeVec ( keyMatrix );
}
else
{
IDOS->Printf( "Error: Could not allocate keymatrix memory\n" );
}
IExec->CloseDevice ( ( struct IORequest * ) KeyIO );
}
else
{
IDOS->Printf( "Error: Could not open keyboard.device\n" );
}
IExec->FreeSysObject ( ASOT_IOREQUEST, KeyIO );
}
else
{
IDOS->Printf( "Error: Could not create I/O request\n" );
}
IExec->FreeSysObject ( ASOT_PORT, KeyMP );
}
else
{
IDOS->Printf( "Error: Could not create message port\n" );
}
return ( 0 );
}