Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino USB HID Keyboard - Updated code


  • Please log in to reply
10 replies to this topic

#1 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 04 August 2011 - 09:04 AM

Here is a quick video of it in action.



This will make the netduino a USB HID, so the netduino will simulate a keyboard in this case.
To get your netduino ready for this:
1 Install firmware 4.1.1 http://forums.netdui...re-v411-beta-1/
2. Transfer to Serial deployment http://forums.netdui...b-and-com1com2/
3. Create a project and put the class in it, add the test code to your program's main method
4. Hook up a usb to serial like this: http://www.sparkfun.com/products/9873 to your netduino's com1 or 2, which ever you chose while setting serial deployment
5. Change deployment in VS to Serial, select your com port
6. Power your netduino with a 9V battery or whatever, except usb. Deploy.
7. You need the code to run and set up the usb stream first, then connect your usb cable.

Class: Attached File  Keyboard.cs   16.63KB   241 downloads

Add a reference to:
Microsoft.SPOT.Hardware.Usb

Sample use. As in the video.
            string setupResult = Keyboard.SetUp();

            Debug.Print(setupResult);

            if (setupResult != "Success")
                return;

            while (true)
            {
                led.Write(true);
                if (button.Read())
                    Keyboard.SendString("/*\n" +
         "* Supported Characters (with this method):\n" +
         "* abcdefghijklmnopqrstuvwxyz\n" +
         "* ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" +
         "* 0123456789\n" +
         "* enter escape backspace deletethis\b\b\b\b\b\b\b\b\b\b \ttab   space\n" +
         "* - = [ { ] } \\ | , > . < / ? ! @ # $ % ^ & * ( )\n" +
         "*/");
                led.Write(false);
                Thread.Sleep(2000);
            }

Projects using the netduino as a keyboard coming sometime soon. I want to make a mouse class next.

I found this:
/* Custom USB HID Communication Device
* Copyright © Secret Labs LLC. All Rights Reserved.
*
*
* Licensed under the Apache 2.0 open source license
*/
in the original code from the USB HID example. I added that I expanded it. I am not big on licenses, but I think I must add it to my code as well. License info here: http://www.apache.or...ICENSE-2.0.html

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 04 August 2011 - 09:14 AM

Ohh very nice! Could be used to make game controllers for the PC for example.
Omar, would it also be possible to add something for combined combinations? For example [Windows key]+R
Perhaps even just use the Sendkeys syntax?

This would give the nice option to do this:
{LWIN}Rhttp://www.netduino.com/

When executing that sequence, the computer would open the Netduino website :D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 04 August 2011 - 09:36 AM

Omar, would it also be possible to add something for combined combinations?


Yeah I am going to work on that. I just wanted to open it up now for people to play with and report bugs to me :) I don't think that the SendKey syntax will be implemented though, its a bit complex and would take a lot of parsing. I want to try and find an easier way to do it.

#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 04 August 2011 - 09:52 AM

I want to try and find an easier way to do it.

I suggest to make a simple syntax for key up, key down, in that case. It would open the possibility for using l/r ctrl, l/r shift, l/r alt, l/r win, etcetera.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#5 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 04 August 2011 - 11:46 AM

Right now I am working on half of a redo in the key system. This feature will let you choose the key modifiers and let them stick. This is how it works as of now: Keyboard.SetModifier(Keyboard.Modifiers.Shift, false); Keyboard.SendString("test"); Will type "Test" Keyboard.SetModifier(Keyboard.Modifiers.Shift, true); Keyboard.SendString("test"); Will type "TEST" So the bool determines if the original modifier of a all of the character's is ignored (true), or just the first (false) So if you want to do a 'Find' you would do: Keyboard.SetModifier(Keyboard.Modifiers.Ctrl, false); // the false means that once the ctrl is pressed with the first key it will be released. Keyboard.SendString("f"); // or Keyboard.SendChar('f'); upper case wouldnt affect it either. and you can do interesting things like Keyboard.SetModifier(Keyboard.Modifiers.Ctrl, false); Keyboard.SendString("fThis is the string i want to find"); // find dialog will show up and "This is the string i want to find" will be typed. Thats all kinda confusing, but you'll see soon. Shift works as explained. Now i have to find the ctrl modifier to test that out ;)

#6 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 04 August 2011 - 12:52 PM

Now you can just press a key (it will be 'held down'). Since keyboards do repeat, the key will be repeated as a regular keyboard does. Things like shift can be 'held down' using the method described above. holding down of keys like the arrow keys might be useful for games.

#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 04 August 2011 - 12:52 PM

I miss an episode... Questions: This project would let the Netduino app to read an USB-keyboard? Was made with the official firmware? If not, could you provide the firmware for the Plus as well? Thank you!
Biggest fault of Netduino? It runs by electricity.

#8 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 04 August 2011 - 01:21 PM

I miss an episode...
Questions:
This project would let the Netduino app to read an USB-keyboard?
Was made with the official firmware? If not, could you provide the firmware for the Plus as well?
Thank you!


Sorry about that ^_^ not everyone is on the same page, my bad. I will update the details above...

EDIT:
I listed a few steps up there. I hope it helps. and just to make it clear, the netduino wont become a host (read keyboard data) it will become a client (be a keyboard).

Edited by Omar (OZ), 04 August 2011 - 01:31 PM.


#9 DanA

DanA

    Member

  • Members
  • PipPip
  • 26 posts

Posted 18 October 2011 - 05:01 PM

Hi,

Thanks for this!

I'm not sure where the official repository for keyboard.cs is - but I added single and double quote support:


case 34:        // "
    cb = 52;
    mod = 0x02;
    break;
case 39:        // '
    cb = 52;
    break;

This is a great reference if there are any keys you need to add for your project: http://www.quadibloc.com/comp/scan.htm

Thanks Again!
Dan

Attached Files



#10 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 19 October 2011 - 10:37 PM

Hi,

Thanks for this!

I'm not sure where the official repository for keyboard.cs is - but I added single and double quote support:


case 34:        // "
    cb = 52;
    mod = 0x02;
    break;
case 39:        // '
    cb = 52;
    break;

This is a great reference if there are any keys you need to add for your project: http://www.quadibloc.com/comp/scan.htm

Thanks Again!
Dan


Thanks for the contribution! I'll add it to the code when i get some time.

#11 David Beauchamp

David Beauchamp

    New Member

  • Members
  • Pip
  • 1 posts
  • LocationShoreline of Connecticut

Posted 02 April 2012 - 07:48 PM

Am I the only one who gets "USB Device Not Recognized" whenever I try to use this? Eventually I saw the note about needing to let the USB code initialize before plugging in the device, so to do that I plugged in my Netduino to a USB hub and let it boot, then I plugged the USB hub unto my computer where it did the device not recognized spiel again but then it also detected a USB keyboard. At this point I was able to use the demo code, however the unrecognized device is still sticking around. If I attempt to boot the Netduino using any other method than the one I described above I can't use it as a keyboard at all. Maybe I am missing something... Thanks, David




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.