ToASCIIEx

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • scruggsy
    New Member
    • Mar 2007
    • 147

    ToASCIIEx

    Hi.
    I am using GetAsyncKeyStat e to read keypresses from another process. I need to be able to convert the scan codes to characters. The code below correctly grabs the input but ToASCIIEx refuses to take the shift keys into account, so I'm unable to get shifted characters.

    Code:
    char TextInputBox::GetKeyPressed()
    {
    	//Doesn't look practical to access Oblivion's keyboard state, so build our own lpKeyState and pass to ToAsciiEx()
    	//(Need to loop through most of the keys anyway to determine which are pressed)
    
    	static HKL keyboardLayout = 0;
    	UInt8 keyboardState[256] = { 0 };
    	static UInt8 lastKeyPressed = 0;
    	UInt8 curKeyPressed = 0;
    	unsigned short charBuffer[2];
    	short keyState = 0;
    
    	for (UInt32 vkCode = 0; vkCode < 256; vkCode++)
    	{
    		keyState = GetAsyncKeyState(vkCode);
    		keyboardState[vkCode] = keyState;
    		if (!curKeyPressed)
    		{
    			if ((keyState & 0x8000) && IsKeyValidChar(vkCode))	//key is pressed
    			{
    				if (vkCode != lastKeyPressed)
    				{
    					curKeyPressed = vkCode;
    				}
    			}
    		}
    	}
    	if (curKeyPressed || !lastKeyPressed)
    		lastKeyPressed = curKeyPressed;
    
    	if (!keyboardLayout)
    		keyboardLayout = GetKeyboardLayout(0);
    
    	if (ToAsciiEx(curKeyPressed, MapVirtualKeyEx(curKeyPressed, 0, keyboardLayout), keyboardState, charBuffer, 0, keyboardLayout) == 1)
    	{
    		_MESSAGE("Character: %c", charBuffer[0]);
    		return charBuffer[0];
    	}
    	else
    	{
    		_MESSAGE("No character");
    		return '\0';
    	}
    }
    What do I need to do to get ToASCIIEx to return shifted characters?
  • scruggsy
    New Member
    • Mar 2007
    • 147

    #2
    Never mind, I figured out my mistake.

    Comment

    Working...