venta: (Default)
[personal profile] venta
Any help appreciated. Do not click on the link unless you want tedious programming waffle.

I currently have a Windows Forms app which presents to the user some buttons. You click on a button, then press a key on the keyboard, and the name of the key you just pressed shows up as the text on the button. (OK, the app does a few other things but they're not important right now).

This all works fine. Unless the key you pressed is the space bar. In which case the string 'Space' will appear on the button for as long as you hold down the space key - as soon as you release it, the key up event is interpreted as a mouse click and the button returns to expecting you to press a key.

I have no idea how to persuade my app to stop (briefly) regarding space-bar-up as a mouse click. I could put special case handling in the click method to check they type of the event, but I'd rather not do that:

(a) it's ugly
(b) it'd require the addition of an if statement to every click method
(c) it'd stop the space-bar-up being interpreted as a mouse click in other situations where it would be perfectly legit[*].

Answers do not include:

(i) Setting the IsInputKey field of the preview key args to 'true'. I'm already doing this in the PreviewKeyDown method, and it's what allows the return key to work nicely. Doesn't seem to help with space though.

(ii) Setting the event's status to 'handled'. I currently have KeyDown and KeyPress methods which are called, and which set e->Handled to 'true'. It doesn't make a blind bit of difference to whether the click method is called or not.

I've spent most of the day googling around the subject, and either I'm very stupid (or have poor google-fu today), or there's not much out there. There's lots about "special keys" and how to interpret them as regular input (see (i) above), but I've not found anything about space - beyond occasional pages commenting that the space bar will be interpreted as a mouse click. Which I hadn't known until today.

Date: 2008-03-18 10:32 am (UTC)
From: [identity profile] venta.livejournal.com
I fear you're very probably right. Being able to set the IsInputKey field is perfectly legitimate mechanism I think - it forces .NET to treat the key like a regular keypress and nothing special. So it's all be nice and friendly if it seemed to apply to the space bar as well as to return, alt, etc.

Profile

venta: (Default)
venta

December 2025

S M T W T F S
 123456
78910111213
14151617181920
212223 24252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 27th, 2025 09:21 am
Powered by Dreamwidth Studios