[comp.sys.amiga.programmer] Converting RAWKEY to ASCII, a request for a How To??

baronz@caen.engin.umich.edu (Aaron L Richards) (04/18/91)

Hello all,

	I was wondering if I might humbly ask the assistance of the combined
Knowledge of the Net in a programming problem upon which I have dwelt for
a number of evenings.

I am using Lattice 5.0. (Not completely ANSI compliant, so I have made
alterations from the code found in the 1.3RKM to make it K&R compatible.)

What I would like to do is take IntuiMessage RAWKEY events and feed them into
 the routine DeadKeyConvert() found on page 197 of the 1.3RKM. and have it
 return an ASCII sequence back in the form of a character if a character key
 was stuck, or a couple characters representing a cursor key, function key,
etc.  As far as I can tell it is not returning anything.  If anyone can point
out my errors, I would appreciate it.

	The program returns rawkey events correctly as can be seen from
the output.  It just seems that the DeadKeyConvert() routine does not seem
to touch the string pointed to by *buffer.

******************************
*** Program Segments Below ***
******************************

**************************************************************************
**** I've included the NewWindow struct to show setting of IDCMP Flags ***
**************************************************************************


/* Declare and initialize the NewWindow structure: */
ecode just cursor key events from
		  ** the RAWKEY events, but I seem to be able to get only
		  ** Vanilla or Raw, not both */

 
  MOUSEBUTTONS|	  /* Sends Mouse up/Down and Menu up/down events	 */  
  RAWKEY,         /*             We will also recieve a message whenever */
                  /*             the user presses/releases a key.        */
	...
	...
	...
};



/*************** This is for the ConvertDeadKey/ConvertRawKey funct ***/

struct ConsoleDevice *ConsoleDevice=NULL;
struct IOStdReq ioreq;


/********************************************************/



LONG DeadKeyConvert(msg,kbuffer,kbsize,kmap) 	/* From RKM pg 197 */

	struct IntuiMessage *msg;
	char *kbuffer;
	LONG kbsize;
	struct KeyMap *kmap;

{
static struct InputEvent ievent={NULL, IECLASS_RAWKEY,0,0,0};

if (msg->Class !=RAWKEY)
	return(-2);

ievent.ie_Code=msg->Qualifier;

ievent.ie_position.ie_addr=*((APTR*)msg->IAddress);

return(RawKeyConvert(&ievent,kbuffer,kbsize,kmap));

}


/********************************************************/



void main()	/* This segment is just to show variables defined/used */

{

  /* Boolean variable used for the while loop: */
  BOOL close_me;
  ULONG class;      /* IDCMP flag. */
  USHORT code;      /* Code. */
  USHORT Qualifier; /* Qualifier */
  char *buffer="This is the string to end all strings "; /* To hold ASCII code representations */
  LONG count;   /* Length of key string returned by DeadKeyConvert */



/***** Necessary for RawKeyConvert ***/
/**/
/**/  if (OpenDevice("console.device",-1L,(struct IORequest *)&ioreq, 0L))
/**/	printf("Could not open the Console.device");
/**/
/**/  ConsoleDevice=(struct ConsoleDevice *)ioreq.io_Device;
/**/
/****************************************************************/


	case RAWKEY:	/* A RAWKEY message has arrived! */
		printf("%d =Qualifier  \n",Qualifier);
		printf("%d =Code\n",code);
		count=DeadKeyConvert(my_message,(UBYTE *)buffer,10,0L);
		printf("%s =string\n",buffer);
		printf("The count is %d\n",count);
		break;

The program reaches the case statement and prints the following while I strike
the keyboard:

32768 =Qualifier  
32 =Code
This is the string to end all strings  =string
The count is 0
...
...


I apologize for the length of this post, but I wanted to be as complete as
necessary.  Thank you for your assistance and have a good day.

--
*	President MACRO on Campus			  	    * 
*       (Michigan's Amiga Computer Resource Organization)           * 
*	Senior Computer Consultant -> Organizational Studies Lab    *
*	Amiga Student Representative on Campus		 	    * 
*	baronz@caen.engin.umich.edu 			   	    *
*	Ph: Day 8-5 (313) 763-4563 Eve 2AM-7:30 761-7871	    *

peter@cbmvax.commodore.com (Peter Cherna) (04/18/91)

In article <1991Apr18.100248.9117@engin.umich.edu> baronz@caen.engin.umich.edu (Aaron L Richards) writes:

>LONG DeadKeyConvert(msg,kbuffer,kbsize,kmap) 	/* From RKM pg 197 */

...

>ievent.ie_Code=msg->Qualifier;

This should be two lines, namely:

ievent.ie_Code=msg->Code;
ievent.ie_Qualifier=msg->Qualifier;



Incidentally, starting with 2.0, if you set both RAWKEY and VANILLAKEY
IDCMP flags, you will receive a VANILLAKEY message if the key pressed
can be represented as a VANILLAKEY, and you'll hear a RAWKEY otherwise.

     Peter
--
Peter Cherna, Operating Systems Development Group, Commodore-Amiga, Inc.
{uunet|rutgers}!cbmvax!peter    peter@cbmvax.commodore.com
My opinions do not necessarily represent the opinions of my employer.
"If all you have is a hammer, everything looks like a nail."