KeyEventHandler works in one dialog but not other ????

L

Lcubed

Hello, hoping some one can shed some light on this. I'm trying to
catch the hardware application keys.

I've tried the following code with and without KeyPreview. The
identical code works in another dialog. The dialog where the code
works is closed and disposed of before the dialog where the code
doesn't work is called.

this.KeyPreview = true;
this.KeyUp += new KeyEventHandler(Form_KeyUp);

void Form_KeyUp(object sender, KeyEventArgs e)
{
LogIt("KeyUp " + e.KeyCode.ToString()); // writes line to debug
file
}

I'm trying to catch the application keys and use a switch like this,
but the function is never entered for the application keys in dialog
that doesn't work. The working dialog captures all the keys.

switch ((HardwareKeys)e.KeyCode)
{
case HardwareKeys.ApplicationKey1:
// do stuff
break;
case HardwareKeys.ApplicationKey2:
// do stuff
break;
}

Does anyone have any ideas as to why this code would work in one
dialog but not in another one in the same application? I'm working
with WM 5.0, .NETCF 3.5.

Thanks for any suggestions!
 
A

Alberto Silva, MVP

Are you sure that you have the KeyPreview form property of the 2nd dialog
set to True?

Alberto Silva

Lcubed said:
Hello, hoping some one can shed some light on this. I'm trying to
catch the hardware application keys.

I've tried the following code with and without KeyPreview. The
identical code works in another dialog. The dialog where the code
works is closed and disposed of before the dialog where the code
doesn't work is called.

this.KeyPreview = true;
this.KeyUp += new KeyEventHandler(Form_KeyUp);

void Form_KeyUp(object sender, KeyEventArgs e)
{
LogIt("KeyUp " + e.KeyCode.ToString()); // writes line to debug
file
}

I'm trying to catch the application keys and use a switch like this,
but the function is never entered for the application keys in dialog
that doesn't work. The working dialog captures all the keys.

switch ((HardwareKeys)e.KeyCode)
{
case HardwareKeys.ApplicationKey1:
// do stuff
break;
case HardwareKeys.ApplicationKey2:
// do stuff
break;
}

Does anyone have any ideas as to why this code would work in one
dialog but not in another one in the same application? I'm working
with WM 5.0, .NETCF 3.5.

Thanks for any suggestions!

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4591 (20091110) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4591 (20091110) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
L

Lcubed

Yes, actually I've tried several variations, all with the same result:
True in both, true in 2nd only, true in 1st only, not set in either
one. No matter how I set it, the first dialog works and the second
does not.

I set the variable as soon as the dialog is instantiated.

public MyDialog()
{
InitializeComponent();

// tried putting this in InitializeComponent as well
// doesn't work either way
this.KeyPreview = true;
this.KeyUp += new KeyEventHandler(Form_KeyUp);
}

I've also tried KeyDown and KeyPress with the same results.
 
L

Lcubed

Still haven't gotten this handler to work. I notice that the up/down/
left/right/enter keys trigger the event, but not the application keys.
The application keys will trigger the event in the first dialog, just
not the second.

Any ideas?

Thanks!
 
A

Alberto Silva, MVP

Hi,
It's strange that you can catch only some keys... what are the application
keys you are talking about, is it a specific device?

Alberto Silva

Lcubed said:
Still haven't gotten this handler to work. I notice that the up/down/
left/right/enter keys trigger the event, but not the application keys.
The application keys will trigger the event in the first dialog, just
not the second.

Any ideas?

Thanks!

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4599 (20091112) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4603 (20091113) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
L

Lcubed

Hi Alberto, Thanks for the reply!

The keys I'm looking for are the four application keys on the front of
the unit, like an Acer, HP iPaq, NEC, Toshiba, Socket, etc... WIndows
Mobile PPCs that don't have a hard key keyboard built in, but do have
an arrow pad and four application keys on the front of the unit. I can
catch the keypad keys but not the application keys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top