Exemple #1
0
//Parse USB input data,translate it into kernel message,and delivery it to HelloX kernel.
static BOOL DoKeyboardMessage(__USB_KEYBOARD_DATA* pKeyboardData)
{
	static KEY_INFO  s_szCurKeyInfo[6] = { 0 };
	LPBYTE    pUsbScanCode = usb_scancode_shiftup;
	BYTE      bCtrlKeyState = pKeyboardData->KeycodeBuffer[0];
	INT       i = 0;

	//check shift is down
	if (bCtrlKeyState&KEY_SHIFT_FLAGE)
	{
		pUsbScanCode = usb_scancode_shiftdown;
	}

	//handle  all scan codes
	for (i = 0; i<MAX_SCANECODE_NUM; i++)
	{
		BYTE       bKeyScancode = pKeyboardData->KeycodeBuffer[i + SCANCODE_START];
		KEY_INFO*  pCurKeyInfo = &s_szCurKeyInfo[i];
		BOOL       bVisableCode = FALSE;
		BYTE       bKeyCode = 0;

		//Get real keycode
		bKeyCode = pUsbScanCode[bKeyScancode];

		if (bKeyCode != 0)
		{
			pCurKeyInfo->bKeyCode = bKeyCode;
			pCurKeyInfo->bScanCode = bKeyScancode;

			bVisableCode = IsVisableKey(bKeyScancode);

			OnKeyHandler(bKeyCode, bVisableCode, KEY_DWON, bCtrlKeyState);
		}
		else
		{
			//key release
			if (pCurKeyInfo->bKeyCode)
			{
				bVisableCode = IsVisableKey(pCurKeyInfo->bScanCode);

				OnKeyHandler(pCurKeyInfo->bKeyCode, bVisableCode, KEY_UP, bCtrlKeyState);
				pCurKeyInfo->bKeyCode = 0;
			}
		}
	}

	/*_hx_printf("USB input data: %X %X %X %X %X %X %X %X.\r\n",
	pKeyboardData->KeycodeBuffer[0],
	pKeyboardData->KeycodeBuffer[1],
	pKeyboardData->KeycodeBuffer[2],
	pKeyboardData->KeycodeBuffer[3],
	pKeyboardData->KeycodeBuffer[4],
	pKeyboardData->KeycodeBuffer[5],
	pKeyboardData->KeycodeBuffer[6],
	pKeyboardData->KeycodeBuffer[7]
	);*/

	return TRUE;
}
Exemple #2
0
//-----------------------------------------------------------
//send f keys to onkey handler
bool ProcessFuncKey(CString k)
{
	//talke a copy
	CString temp=k;

	//get count value & strip out count characters
	//from temporary value
	int count=GetFunctionKeyCount(k);

	//is it a function key?
	if (IsAFunctionKey(k) || k.Pos("\\")==1)
	{
		//pass it count times to handler
		for(int i=0;i<count;i++)
		{
			OnKeyHandler(true,k);
		}
		return true;
	}
	else
	{
		//restore original if not an F key
		k=temp;
	}

	return false;
}
Exemple #3
0
//-----------------------------------------------------------
void __PushKeys(const char* src)
{

	//Copyright by Data Solutions Pty Ltd (ACN 010 951 498)
	//All rights reserved.
	//Email for info: [email protected]


	// This is the routine that does all the work
	int index;
	CString SubStr;
	INT BrCnt;
	CHAR BrOpen;
	CHAR BrClose;
	CHAR Ch;
	CHAR nextCh;

	int srcLen=strlen(src);
	if (srcLen == 0)
		return;

	char ck[]={'+','^','%','!'};
	void (*ckonfuncs[])()={SHIFTOn,CTRLOn,ALTOn,RALTOn};
	void (*ckofffuncs[])()={SHIFTOff,CTRLOff,ALTOff,RALTOff};

	index = 0;
	while (index<srcLen)
	{
		char nextCh = src[index + 1];

		// control keys & functions
		bool controlkey = false;
		int ckidx;

		//is it a control key next?
		for (int ckidx = 0; ckidx < sizeof(ck) / sizeof(*ck); ckidx++)
		{
			if (nextCh == ck[ckidx])
			{
				//contol key alone?
				if (srcLen == 1)
				{
					//turn control key on
					(*ckonfuncs[ckidx])();

					//control key off
					(*ckofffuncs[ckidx])();

					//exit
					return;
				}

				controlkey=true;
				break;
			}
		}

		//shift,ctrl,alt,ralt found
		if (controlkey && srcLen>=index+2)
		{
			BrOpen=src[index+2];
			if ((BrOpen=='(')||(BrOpen=='{'))
			{
				if (BrOpen=='(')
				{
					BrClose=')';
				}
				else
				{
					BrClose='}';
				}
				index++;
				SubStr="";
				BrCnt=1;
				while ((index<srcLen-1)&&(BrCnt!=0))
				{
					index++;
					Ch=src[index+1];

					if (Ch!=BrClose)
					{
						SubStr+=Ch;
					}
					else 
					{
						BrCnt--;
					}
					if (Ch==BrOpen)
						BrCnt++;
				}

				// Turn control key on
				(*ckonfuncs[ckidx])();

				// Push the keys
				if (SubStr!="")
				{
					if (BrOpen=='(')
					{
						__PushKeys(SubStr);
					}
					else
					{
						CString t=SubStr;
						if(ProcessFuncKey(t))
						{
							t="";
						}

						if (t.GetLength()>0)
							PushFnKey(t);
					}
				}
				// Turn control key off
				(*ckofffuncs[ckidx])();
			}
			else
			{
				// The next key uses control
				index++;
				(*ckonfuncs[ckidx])();

				OnKeyHandler(false,src[index+1]);
				(*ckofffuncs[ckidx])();
			}

		}
		else if (nextCh=='{' && src!="{}" && src!="}{")
		{
			// Function keys
			index++;
			SubStr="";

			while ((index<(srcLen-1))&&(src[index+1]!='}'))
			{
				SubStr+=src[index+1];
				index++;
			}

			if(srcLen>1)
			{
				if (src[srcLen]=='}' && src[srcLen-1]=='}')
				{
					// Right brace
					OnKeyHandler(false,'}');
					PushAKey('}');
					index++;
				}
				else
				{
					CString k=SubStr;
					if (ProcessFuncKey(k))
					{
						k="";
					}
					else if(k.UpperCase().Pos("SLEEP")==1)
					{
						//sleep
						OnKeyHandler(false,k);
					}
					//****************************************
					//clear clipboard
					else if (k.UpperCase().Pos("EMPTYCLIP")==1)
					{
						OnKeyHandler(false,k);
					}
					//run
					else if (k.UpperCase().Pos("RUN ")==1)
					{
						OnKeyHandler(false,k);
					}

					//not a function key (a 3} type of thing
					if(k.GetLength()>0)
					{
						PushFnKey(k);
					}
				}
			}
		}
		else if (nextCh=='~')
		{
			// The enter key
			ProcessFuncKey("ENTER");
		}
		else
		{
			OnKeyHandler(false,nextCh);
		}
		index++;
	}

	//turn all control keys off
	AllOff();

}
Exemple #4
0
//-----------------------------------------------------------
//function keys
void PushFnKey(CString KeyCode)
{

	// Outputs function key. KeyCode may have a number of times to be output
	LONG NumPushes;
	INT index;
	CString FnKey;
	CString OrigCode;
	bool isfnkey=false;

	// Work out which function key to push and how many times

	//get key press count & strip out count characters
	NumPushes=GetFunctionKeyCount(KeyCode);

	//keep a copy
	OrigCode=KeyCode;

	FnKey=KeyCode.UpperCase();

	//direct code entry
	if (FnKey.Pos("\\")==1)
	{
		ProcessFuncKey(FnKey);
		return;
	}

	//braces
	if (FnKey=="LEFTBRACE" || FnKey=="RIGHTBRACE")
	{
		char pc=FnKey.Pos("LEFT")<1 ? '}' : '{';
		for (index=1;index<=NumPushes;index++)
		{
			PushAKey(pc);
		}
		return;
	}

	//search for F key
	byte fnkey=GetFunctionKey(FnKey);

	if (fnkey==(byte)-1)
		fnkey=GetControlKey(FnKey);

	if (fnkey!=(byte)-1)
	{
		isfnkey=true;
	}

	//press f key
	if (isfnkey)
	{
		bool dodos=false;

		//do DOS conversion?
		if (DOSKey)
		{
			byte vk[]={VK_BELL,VK_BREAK,VK_RETURN,VK_ESCAPE,VK_CLEAR,VK_LINEFEED,VK_TAB};
			char dk[]={'G','C','M','[','L','J','I'};

			//search for key equivalent
			for (int i=0;i<sizeof(vk)/sizeof(vk[0]);i++)
			{
				if (fnkey==vk[i])
				{
					//match found
					dodos=true;

					for (index=1;index<=NumPushes;index++)
					{
						//do key press
						PushCTRLKey(dk[i]);
					}
					break;
				}
			}
		}
		if (!dodos)//normal fkey
		{
			for (index=1;index<=NumPushes;index++)
			{
				//reserved characters
				if (GetControlKey(fnkey)!=(byte)-1)
				{
					PushAKey(fnkey);
				}
				else
				{
					//full printscreen
					if (fnkey==VK_SNAPSHOT && !AltOn)
					{
						PressKey(fnkey,1);
					}
					else
					{
						PressKey(fnkey,MapVirtualKey(fnkey,0));
					}
				}
			}
		}
	}
	//sleeep or NL or clear clipboard or run
	else if(FnKey!="SLEEP" && FnKey!="NEWLINE" && FnKey!="NL"  && FnKey !="EMPTYCLIP"
		&& FnKey.Pos("RUN ")!=1)
	{
		// Ordinary keys
		for (index=1; index<=NumPushes; index++)
		{
			for (int i=0;i<OrigCode.GetLength();i++)
			{
				char ss=OrigCode[i+1];

				//watch for {~ 2}
				if(ss!='~' || OrigCode=="~")
				{
					OnKeyHandler(false,ss);
				}
				else
				{
					//{hello world~ 3}
					OnKeyHandler(true,"ENTER");
				}
			}
		}
	}
}