Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

0 views
Skip to first unread message

Lcubed

unread,
Nov 9, 2009, 4:45:25 PM11/9/09
to
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!

Alberto Silva, MVP

unread,
Nov 10, 2009, 6:39:46 AM11/10/09
to
Are you sure that you have the KeyPreview form property of the 2nd dialog
set to True?

Alberto Silva

"Lcubed" <loris.e...@gmail.com> escreveu na mensagem
news:fd77c489-d39c-4c02...@p8g2000yqb.googlegroups.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
>
>
>

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

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Lcubed

unread,
Nov 10, 2009, 8:59:34 AM11/10/09
to
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.

On Nov 10, 6:39 am, "Alberto Silva, MVP"


<albertosi...@mundomovel.removeuntildot.com> wrote:
> Are you sure that you have the KeyPreview form property of the 2nd dialog
> set to True?
>
> Alberto Silva
>

> "Lcubed" <loris.email...@gmail.com> escreveu na mensagemnews:fd77c489-d39c-4c02...@p8g2000yqb.googlegroups.com...

Lcubed

unread,
Nov 11, 2009, 5:21:34 PM11/11/09
to
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!

Alberto Silva, MVP

unread,
Nov 13, 2009, 5:52:30 AM11/13/09
to
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" <loris.e...@gmail.com> escreveu na mensagem

news:59c34687-f1bd-4de9...@15g2000yqy.googlegroups.com...

> __________ 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) __________

Lcubed

unread,
Nov 16, 2009, 9:24:52 AM11/16/09
to
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.


On Nov 13, 5:52 am, "Alberto Silva, MVP"


<albertosi...@mundomovel.removeuntildot.com> wrote:
> 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" <loris.email...@gmail.com> escreveu na mensagemnews:59c34687-f1bd-4de9...@15g2000yqy.googlegroups.com...

0 new messages