I’m trying ways to detect the PC kybd arrow keys (the four left/right/up down keys, NOT the ones on the numeric pad)…The following code works fine if I use .P or .Q keys, but does not work if I use .DownArrow or .UpArrow They are all listed as selectable enumerated choices…what’s wrong?
if (hhh==ddd.GetKeyState(USBH_Key.DownArrow)) arrowtype=1;
else
if (hhh == ddd.GetKeyState(USBH_Key.UpArrow)) arrowtype = 2;
@ Hoyt - I have been doing quite a bit of work with a USB connected keyboard recently and have not had any issues with the arrow keys. I quickly put together the following piece of code using the Gadgeteer infrastructure, the following worked for me. Do you see any differences with what you are doing?
using System.Threading;
using Microsoft.SPOT;
using Gadgeteer.Modules.GHIElectronics;
namespace UsbKeyboardTest
{
public partial class Program
{
void ProgramStarted()
{
usbHost.KeyboardConnected += new UsbHost.KeyboardConnectedEventHandler(usbHost_KeyboardConnected);
Debug.Print("Program Started");
}
void usbHost_KeyboardConnected(UsbHost sender, GHIElectronics.NETMF.USBHost.USBH_Keyboard Keyboard)
{
new Thread(
() =>
{
bool running = true;
while (running)
{
if (Keyboard.GetKeyState(GHIElectronics.NETMF.USBHost.USBH_Key.UpArrow) == GHIElectronics.NETMF.USBHost.USBH_KeyState.Down)
{
Debug.Print("Up arrow");
}
if (Keyboard.GetKeyState(GHIElectronics.NETMF.USBHost.USBH_Key.DownArrow) == GHIElectronics.NETMF.USBHost.USBH_KeyState.Down)
{
Debug.Print("Down arrow");
}
if (Keyboard.GetKeyState(GHIElectronics.NETMF.USBHost.USBH_Key.Escape) == GHIElectronics.NETMF.USBHost.USBH_KeyState.Down)
{
Debug.Print("Done.");
running = false;
}
}
}).Start();
}
}
}
Thanks.—your help led me to look again…I originally set some other code events to use CharDown…weeks later I wanted to use the arrow keys, but they only trigger KeyDown, so a simple change elsewhere fixed it. Chardown only triggers on ascii chars.