Results 1 to 6 of 6

Thread: USB Button

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    USB Button

    Hey,
    I'm wondering if there are any external buttons I can control with VB.NET.

    I want a Ok and Cancel button that the user can physically press.
    These are the only commands required to interact with the app so I want to be able to detect in VB what button is pressed.

    Can anyone help me find one that works with VB?
    Obviously, I need to be able to attach two to the same PC.
    Last edited by vixez; Feb 10th, 2012 at 02:16 PM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: USB Button

    you should already have them... they're called the Enter (OK) and ESC (Cancel) keys... on the form... there is a pair of Properties: AcceptButton and CancelButton... set the AcceptButton to the OK button, and the CancelButton to the Cancel button... and you're all set.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,395

    Re: USB Button

    I think what you're looking for is the button's click event. Either double click on the ok(or cancel) button and that will bring it up, or press F7 and in the upper left-hand corner(Should say general) chose your ok(or cancel) button and in then in the upper right-hand corner(Should say declerations) chose the click event.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Re: USB Button

    Sorry, I think I didnt explain properly.
    I want two physical buttons connected to a PC by USB or any other means.
    One has the function of OK, the other of Cancel.
    There is no keyboard or mouse connected to the PC, so the user can only press those two buttons.

    Now what I want to know is: Where can I buy such buttons, and how can I make my app recognize which of the two button is pressed?

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,395

    Re: USB Button

    After googling a bit, I found this. Gotta say, it's something I'm kinda intrested in. The article is in c#, but there are a number of free converters. Just google C# to vb.net, and I allways use the first link that comes up.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  6. #6
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: USB Button

    The simple way is to use a USB serial port adapter. A RS-232 serial port has three inputs that can be used to monitor an external button press. Connect pin4 (DTR) to one side of a button. Connect one of the following pins to the other side of the button, pin1 (DCD), pin6 (DSR) or pin8 (CTS).

    Add a SerialPort control to your program. Set the PortName and call the Open method.

    The SerialPort PinChanged event is generated whenever an input line changes state, which will happen when the button is pushed or released. You can test the CDHolding, DSRHolding or CTSHolding properties (respectively for the pins used above) to determine line state.

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width