Detect quickest keypress (gameshow buzzers)

Posted on 2012-08-14
Medium Priority
Last Modified: 2012-08-20

I've got hardware for presenting gameshow buzzers as keyboard input. For testing/writing I'm just using my keyboard to do the sme thing.

I need to determine which contestant buzzed first, which is easy enough using a keypress or keydown event on a textbox for example. (I got a bool vBuzzed which starts false, and the first keypress sets it to true before doing the rest of my code.

However, if 2 buttons are pressed simultaneously, it is ignoring both of them completely. Even if I remove the key events and just watch the textbox, test doesn't appear, which defies the issue of determining quickest buzzer...

Is there a way I can make the app see (and thus detect) these simultaneous presses?

Question by:howartp
  • 3
LVL 16

Expert Comment

ID: 38295083
I'm not able to test with VB.Net at this very moment, but in every windows application I attempt to utilize, it never tosses two keys pressed simultaniously.  Both keys always register.

Is there some way that your logic could be tossing both key events away?  Specifically, what is your code doing in the key events?  

Without the ability to do additional testing at this moment, about the only thing that comes to mind is that you are setting vBuzzed to true on the 1st key event and ignoring all key events when vBuzzed is true.  In that situation, I could see where it would be possible for the operating system to do something unexpected to confuse your logic.  For example, it might first send a NULL key event (because two keys were pressed simultaniously) followed by two more events, one for each of the two keys... or the events might execute simultaniously, and you have the equivilent of a multi-threaded race condition (i.e. both events execute set the vBuzzed flag, then both read the vBuzzed flag and ignore itself).  

Without seeing a specific code example, I'm just shooting in the dark here.

If you are indeed attempting to "deactivate" key events with the 1st key pressed, I would instead suggest that the key events append the key to a Form level string... then simply look at which key comes before the other in the string.

Author Comment

ID: 38297448

    Private Sub tbBuzzers_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles tbBuzzers.KeyPress
        If (Not vBuzzed) And ((e.KeyChar = "0") Or (e.KeyChar = "1") Or (e.KeyChar = "2")) Then
            vBuzzed = True
            If e.KeyChar = "0" Then
            ElseIf e.KeyChar = "1" Then
            ElseIf e.KeyChar = "2" Then

            End If
            e.Handled = True
        End If
    End Sub

Open in new window

This is the original code I had in, which is what I have used in a similar circumstance for another gameshow about 5 years ago.

Does it look ok?

I am half-remembering that I had a similar issue when initially programming it back then, which would have been away from home on a laptop, but when I got back home I've a feeling the issue disappeared - so I'm wondering if the laptop is blocking simultaneous keys at hardware/driver level before they even get to Windows...

If the code looks ok, I'll wait till I get home at the weekend and check the same code on my PC.


[Edit:  Copied wrong copy of the sub-routine]

Accepted Solution

howartp earned 0 total points
ID: 38297533
In fact, I've just realised that it's my Kensington USB Keyboard which is surpressing the multiple keypresses - if I press them directly on the laptop's keyboard then they work as intended.

So, apologies for wasting your time.


Author Closing Comment

ID: 38310990
In fact, I've just realised that it's my Kensington USB Keyboard which is surpressing the multiple keypresses - if I press them directly on the laptop's keyboard then they work as intended.

So, apologies for wasting your time.


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question