1

I'm wondering if there's an easy way to tell which input device triggered a particular GUI event.

For example: A TButton.OnClick event gets fired. Did the user trigger it with a keyboard press (shortcut, Enter key for default button, space key for a focused button, etc.) or was it triggered with a mouse click? Is there any easy way to tell?

The reason I'd like to know is so that I can implement keyboard usage hints into some of our applications when the user uses the mouse to initiate actions that could also be done with the keyboard. Our systems on the shop floor are in pretty dusty/dirty environments, and mice tend to not hold up so well in them. Also, in many cases, there's simply not that much room for a mouse to be used. (No, keyboards without numeric keypads is not a solution. They're relied on too heavily.)

However, since our apps run in Windows, users tend to simply use the programs like they would at home -- with a mouse. There's nothing particularly wrong with that, but we've worked hard to optimize the input workflow to be keyboard friendly as well. It'd be nice if there was a low-impact way to indicate to our users that there's a way for them to do the things they're doing without having to grab the mouse.

afrazier
  • 4,784
  • 2
  • 27
  • 30
  • Why not use the standard ways to indicate keyboard access? – David Heffernan Jan 27 '12 at 19:20
  • @DavidHeffernan: Such as? I employ standard keyboard shortcuts when possible, use default buttons, use `TAction` (or descendants) to back my UI actions as much as possible. However, I've only got so much screen space, I can't dedicate it to adding shortcut information all over the UI. I'd like to be able to have a hint show on screen when a user clicks the "Add Item" button that says: "You can also press `Insert` to add an item." – afrazier Jan 27 '12 at 19:48
  • Show shortcuts in hints. The VCL does that for you. Use accelerator keys. Let the user discover it themselves. Don't force in on them. – David Heffernan Jan 27 '12 at 21:02
  • @DavidHeffernan: Accelerators are available, but remember that they're hidden by default in Windows. I'm thinking of using a hint-style popup -- I don't want to interfere with what they're doing, but do want to draw their attention momentarily. The objective is to make keyboard usage more discoverable without being annoying. Standard hints don't work because users tend to move the mouse pointer out of the way after clicking on something in my observation (which, admittedly, is anecdotal rather than rigorous), or they're moving the mouse pointer to the next target. – afrazier Jan 27 '12 at 21:10
  • Related: [What is the best way to get users to discover and learn keyboard shortcuts](http://ux.stackexchange.com/questions/9336/what-is-the-best-way-to-get-users-to-discover-and-learn-keyboard-shortcuts) – afrazier Jan 27 '12 at 21:18
  • by and large users don't want to use the keyboard. Those that do will find out. You've nothing to worry about. – David Heffernan Jan 27 '12 at 22:01

1 Answers1

4

There's no way to tell from within OnClick. However, you can also attach events to a control that will fire when the mouse rolls over it, which would probably be more appropriate for what you're trying to do anyway. Take a look at the OnMouseEnter and OnMouseLeave events. Also, if you really want something specific to happen when the mouse is clicked, you can attach it to OnMouseUp.

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
  • ...and/or `OnMouseDown`. Sounds reasonable! – Andriy M Jan 27 '12 at 18:26
  • 1
    @Andriy: `OnMouseDown` isn't such a good idea, from a consistency perspective. Users are used to "clicks" happening when you click *and release* a control. – Mason Wheeler Jan 27 '12 at 18:38
  • 1
    Entirely agree, `OnMouseUp` is definitely a better choice in that regard. But I meant `OnMouseDown` as an alternative (or, perhaps, as a supplement) to `OnMouseUp` in the business of noting down the frequency of using mouse. The main action would still be handled with `OnClick`, which is what I presumed you meant too. I might easily be wrong in my presumption, of course, and I'm sorry if I caused any confusion! – Andriy M Jan 27 '12 at 18:49
  • Looks like I'll have to use some `OnMouse(Enter|Leave|Up)` work to figure it out. I suppose that on one hand, it makes sense to do this kind of input-device-specific work in input-device-specific event handlers (especially since most visual components could probably point at the same event handlers), I just wanted to keep all my code related to a particular action available from that action's implementation at first. – afrazier Jan 27 '12 at 21:21