rem: if(msg->FindInt8("byte",3,utf8data+3)!=B_OK) utf8data[3]=0;
context: handle_message(BPortLink* serverLink, BMessage* msg){	bool handled = true;	switch (msg->what)	{		case B_MOUSE_WHEEL_CHANGED:		{			float x,y;			msg->FindFloat("be:wheel_delta_x",&x);			msg->FindFloat("be:wheel_delta_y",&y);			int64 time=real_time_clock();			serverLink->StartMessage(B_MOUSE_WHEEL_CHANGED);			serverLink->Attach(&time,sizeof(int64));			serverLink->Attach(x);			serverLink->Attach(y);			serverLink->Flush();			break;		}		case B_KEY_DOWN:		{			// Attached Data:			// 1) int64 bigtime_t object of when the message was sent			// 2) int32 raw key code (scancode)			// 3) int32 modifier-independent ASCII code for the character			// 4) int32 repeat count			// 5) int32 modifiers			// 6) int8[3] UTF-8 data generated			// 7) int8 number of bytes to follow containing the 			//		generated string			// 8) Character string generated by the keystroke			// 10) int8[16] state of all keys			bigtime_t systime;			int32 scancode, asciicode,repeatcount,modifiers;			int8 utf8data[4];			BString string;			int8 keyarray[16];						systime=(int64)real_time_clock();			msg->FindInt32("key",&scancode);			if(msg->FindInt32("be:key_repeat",&repeatcount)!=B_OK)			{				// TODO: see if repeatcount should be 0 or 1 when not repeating				repeatcount=1;			}			msg->FindInt32("modifiers",&modifiers);			msg->FindInt32("raw_char",&asciicode);						msg->FindInt8("byte",0,utf8data);			if(msg->FindInt8("byte",1,utf8data+1)!=B_OK)				utf8data[1]=0;			if(msg->FindInt8("byte",2,utf8data+2)!=B_OK)				utf8data[2]=0;			if(msg->FindInt8("byte",3,utf8data+3)!=B_OK)				utf8data[3]=0;			msg->FindString("bytes",&string);			for(int8 i=0;i<15;i++)				msg->FindInt8("states",i,&keyarray[i]);			serverLink->StartMessage(B_KEY_DOWN);			serverLink->Attach(&systime,sizeof(bigtime_t));			serverLink->Attach(scancode);			serverLink->Attach(asciicode);			serverLink->Attach(repeatcount);			serverLink->Attach(modifiers);			serverLink->Attach(utf8data,sizeof(int8)*3);			serverLink->AttachString(string.String());			serverLink->Attach(keyarray,sizeof(int8)*16);			serverLink->Flush();			break;		}		case B_KEY_UP:		{			// Attached Data:			// 1) int64 bigtime_t object of when the message was sent			// 2) int32 raw key code (scancode)			// 3) int32 modifier-independent ASCII code for the character			// 4) int32 modifiers			// 5) int8[3] UTF-8 data generated			// 6) int8 number of bytes to follow containing the 			//		generated string			// 7) Character string generated by the keystroke			// 8) int8[16] state of all keys			bigtime_t systime;			int32 scancode, asciicode,modifiers;			int8 utf8data[3];			BString string;			int8 keyarray[16];			systime=(int64)real_time_clock();			msg->FindInt32("key",&scancode);			msg->FindInt32("raw_char",&asciicode);			msg->FindInt32("modifiers",&modifiers);			msg->FindInt8("byte",0,utf8data);			if(msg->FindInt8("byte",1,utf8data+1)!=B_OK)				utf8data[1]=0;			if(msg->FindInt8("byte",1,utf8data+2)!=B_OK)				utf8data[2]=0;			if(msg->FindInt8("byte",1,utf8data+3)!=B_OK)				utf8data[3]=0;			msg->FindString("bytes",&string);			for(int8 i=0;i<15;i++)				msg->FindInt8("states",i,&keyarray[i]);			serverLink->StartMessage(B_KEY_UP);			serverLink->Attach(&systime,sizeof(bigtime_t));			serverLink->Attach(scancode);			serverLink->Attach(asciicode);			serverLink->Attach(modifiers);			serverLink->Attach(utf8data,sizeof(int8)*3);			serverLink->AttachString(string.String());			serverLink->Attach(keyarray,sizeof(int8)*16);			serverLink->Flush();			break;		}		case B_UNMAPPED_KEY_DOWN:		{			// Attached Data:			// 1) int64 bigtime_t object of when the message was sent			// 2) int32 raw key code (scancode)			// 3) int32 modifiers			// 4) int8[16] state of all keys			bigtime_t systime;			int32 scancode,modifiers;			int8 keyarray[16];			systime=(int64)real_time_clock();			msg->FindInt32("key",&scancode);			msg->FindInt32("modifiers",&modifiers);			for(int8 i=0;i<15;i++)				msg->FindInt8("states",i,&keyarray[i]);			serverLink->StartMessage(B_UNMAPPED_KEY_DOWN);			serverLink->Attach(&systime,sizeof(bigtime_t));			serverLink->Attach(scancode);			serverLink->Attach(modifiers);			serverLink->Attach(keyarray,sizeof(int8)*16);			serverLink->Flush();			break;		}		case B_UNMAPPED_KEY_UP:		{			// Attached Data:			// 1) int64 bigtime_t object of when the message was sent			// 2) int32 raw key code (scancode)			// 3) int32 modifiers			// 4) int8[16] state of all keys			bigtime_t systime;			int32 scancode,modifiers;			int8 keyarray[16];			systime=(int64)real_time_clock();			msg->FindInt32("key",&scancode);			msg->FindInt32("modifiers",&modifiers);			for(int8 i=0;i<15;i++)				msg->FindInt8("states",i,&keyarray[i]);			serverLink->StartMessage(B_UNMAPPED_KEY_UP);			serverLink->Attach(&systime,sizeof(bigtime_t));			serverLink->Attach(scancode);			serverLink->Attach(modifiers);			serverLink->Attach(keyarray,sizeof(int8)*16);			serverLink->Flush();			break;		}		case B_MODIFIERS_CHANGED:		{			// Attached Data:			// 1) int64 bigtime_t object of when the message was sent			// 2) int32 modifiers			// 3) int32 old modifiers			// 4) int8 state of all keys			bigtime_t systime;			int32 scancode,modifiers,oldmodifiers;			int8 keyarray[16];			systime=(int64)real_time_clock();			msg->FindInt32("key",&scancode);			msg->FindInt32("modifiers",&modifiers);			msg->FindInt32("be:old_modifiers",&oldmodifiers);			for(int8 i=0;i<15;i++)				msg->FindInt8("states",i,&keyarray[i]);						serverLink->StartMessage(B_MODIFIERS_CHANGED);			serverLink->Attach(&systime,sizeof(bigtime_t));			serverLink->Attach(scancode);			serverLink->Attach(modifiers);			serverLink->Attach(oldmodifiers);			serverLink->Attach(keyarray,sizeof(int8)*16);			serverLink->Flush();			break;		}		default:			handled = false;;			break;	}	return handled;}