PC Review


Reply
Thread Tools Rate Thread

Consuming the starpad Return button?

 
 
fd123456
Guest
Posts: n/a
 
      6th Nov 2003
Hi all!

In a Form's constructor, I add a KeyEvent handler :

this.KeyDown += new KeyEventHandler(myKeyDown);

And here is myKeyDown :

private void myKeyDown(object sender, KeyEventArgs e)
{
e.Handled=true;
MessageBox.Show(e.KeyCode.ToString());
}

The problem is that if the key pressed is the starpad's middle button
(which, weirdly, is caught as Select AND Return AND F23 by CF), the
event is not consumed, e is not handled, and the MessageBox is closed
because it thinks I'm still pressing Return.

This is a very basic repro, but on a larger scale, it means that you
can not have two successive forms both having the Return key as a
validation, because as soon as the first one calls the second one, the
second one gets validated as well.

Is there a way to consume that OK/Select/Return/F23/middle key event?
I've looked all around and couldn't find anything. Having a loop
waiting for the KeyUp event is not possible, because that event
doesn't get consumed either. And waiting for SP2/3/Whidbey/VS 2018 is
not an option . Has anyone found a workaround?

Thanks for sharing if you have.

Michel.
 
Reply With Quote
 
 
 
 
fd123456
Guest
Posts: n/a
 
      7th Nov 2003
Ok, found a totally inelegant solution...

After InitializeComponent() :

this.KeyDown+=new KeyEventHandler(MyKeyDown);
this.KeyUp+=new KeyEventHandler(MyKeyUp);

In declarations :

private bool IsUp=false;

Anywhere :

private void MyKeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
IsUp=false;
e.Handled=true;
while (IsUp==false) Application.DoEvents();
// do stuff here, eg MessageBox.Show(e.KeyCode.ToString());
}
private void MyKeyUp(object sender, System.Windows.Forms.KeyEventArgs
e)
{
IsUp=true;
}

Drawback : the system waits until you've released the key to carry on
with the rest of the code. I just wish the Handled method worked as
expected.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return Button on the Keyboard guswine8 Microsoft Excel Worksheet Functions 3 8th Nov 2008 04:39 PM
Macro must return the name of the button =?Utf-8?B?RGVyZWsgQnJ1c3NlbHM=?= Microsoft Excel Discussion 3 17th May 2006 11:22 PM
Return Key & Go Button Failure =?Utf-8?B?YWpzZzI=?= Windows XP Internet Explorer 2 22nd Apr 2006 09:50 PM
button to return to top of spreadsheet =?Utf-8?B?Q2luZHkgQg==?= Microsoft Excel Programming 3 8th Mar 2005 02:55 PM
return javascript value from asp.net button =?Utf-8?B?QUNhdW50ZXI=?= Microsoft ASP .NET 4 21st Jan 2005 06:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:51 PM.