Questions on the Keyboard Inputs on the USBHost_t36 Library

Status
Not open for further replies.
Happy New Year Everyone! Here is my project and question related to it.

Project Description:
Converting mouse & keyboard inputs to game controller commands. A Teensy MicroMod is used with an ATP carrier board that has an USB host connector. The USB keyboard and mouse is connected to it via an USB hub. The Teensy takes in the keyboard & mouse command and sends data via UART to an Arduino Leonardo that's emulating an XBox controller. I took the example codes on the Teensy side and got a majority of the code to work but some stuff still needs to be figured out. I can't seem to figure it out myself right now so I thought I'd ask here in the forum.

Questions:
1. Is there a way to detect the following keys being pressed just by itself? Shift, Ctrl, Alt, Tab. What would the syntax be for it?
2. Are there syntaxes to detect when keyboard key presses are being held down and when it's being released?
 
keyboard1.attachRawPress(OnRawPress);
keyboard1.attachRawRelease(OnRawRelease);
These capture all the keys including modifier keys Shift, Ctrl, Alt, Tab and Windows key.

In this part example I send the modifiers keys separately from all other key presses. I send keyboards and mouse commands to multiple PCs/ Pi's via Arduinos , so similar.
Hope this helps a bit.
Regards
Code:
void OnRawPress(uint8_t keycode)
{
	if(debugOEM>0)
	{
		Serial.print("raw key press: ");
		Serial.println((int)keycode);
	}
	//Check if a modifier key
	if((keycode < 110) &&(keycode > 102))
	{
		//its a modifier key.
		switch (keycode)
		{
			case 103:
				modKey = 0x01;
			break;
			case 104:
				modKey = 0x02;
			break;
			case 105:
				modKey = 0x04;
			break;
			case 106:
				modKey = 0x08;
			break;
			case 107:
				modKey = 0x10;
			break;
			case 108:
				modKey = 0x20;
			break;
			case 109:
				modKey = 0x40;
			break;
			case 110:
				modKey = 0x80;
			break;
		}
		//void sendMOD(byte ID, byte modKey, byte prKey )
		if(debugOEM>0)
		{
			Serial.print("Modifier Key Pressed : ");
			Serial.println(modKey, HEX);
			
		}
		sendMOD(remID, modKey, 0x01);
	}
	else
	{
		//sendOEM(remID, Tkey, mod, 0x01)
		sendOEM2(remID, Tkey, 0x01);//sendOEM2 , modifier send seperately.
	}
}
 
keyboard1.attachRawPress(OnRawPress);
keyboard1.attachRawRelease(OnRawRelease);
These capture all the keys including modifier keys Shift, Ctrl, Alt, Tab and Windows key.

Thanks a lot! I put your code and modified it in my test sketch and it's showing a lot of promising results! :D
 
I have another question that I'm wondering if you, @macrosii , or anyone else might know. Its regarding the MouseController mouse1(myusb);.

The mouse1.getMouseX() and mouse1.getMouseY() function seems to return a -127 to 127 max value range no matter how hard I move my mouse. But peaking the definition, it's return type is int (see image attached). Does that mean it can return an absolute value higher than 127? If so how?

Screenshot (17).jpg
 
With the Mouse, it is what your mouse returns... more or less just relative distances moved...

All of this is controlled by the mouse and it's HID definitions. Some may define them as 8 bit others maybe different, but again we simply return what the mouse gives us
 
With the Mouse, it is what your mouse returns... more or less just relative distances moved...

All of this is controlled by the mouse and it's HID definitions. Some may define them as 8 bit others maybe different, but again we simply return what the mouse gives us

Does that mean the 8 bit return value is fixed? If not, what ways can I go about in increasing the return value range? Currently, I find the 8 bit value not giving a good sensitivity feeling on my project testing.
 
Status
Not open for further replies.
Back
Top