Click here to Skip to main content
15,889,462 members
Home / Discussions / C#
   

C#

 
GeneralRe: Writing hexadecimal to a file Pin
Julian Bucknall [MSFT]25-Sep-03 5:03
Julian Bucknall [MSFT]25-Sep-03 5:03 
GeneralSocket Blocking Pin
Andrew Shapira24-Sep-03 14:40
Andrew Shapira24-Sep-03 14:40 
GeneralHelp with regular expressions Pin
Wjousts24-Sep-03 13:17
Wjousts24-Sep-03 13:17 
GeneralRe: Help with regular expressions Pin
Blake Coverett24-Sep-03 13:31
Blake Coverett24-Sep-03 13:31 
GeneralRe: Help with regular expressions Pin
Wjousts24-Sep-03 15:04
Wjousts24-Sep-03 15:04 
GeneralRe: Help with regular expressions Pin
Anthony_Yio24-Sep-03 17:16
Anthony_Yio24-Sep-03 17:16 
GeneralCOM Interop - .NET COM events and C++ client Pin
blade24-Sep-03 12:54
blade24-Sep-03 12:54 
General? The Key Events Pin
Frank Olorin Rizzi24-Sep-03 12:19
Frank Olorin Rizzi24-Sep-03 12:19 
[mode="frustrated"]
ARGH !
[/mode]

Please, please, if you can help with this,
*please* do so: I'm about to loose my mind on it Smile | :)

Here's the problem:

I'm developing a simple WinForm application.
Among other things, I'd like to set a private boolean flag,
called "shiftPressed" to true when the user is pressing
the Shift key.
This flag is checked when doing other things (such as
clicking on the form) to modify the behavior of the application
as needed.

So, I figured the logical thing to do was to
intercept the KeyDown and the KeyUp events.
In the Key down event, I would set the flag to true
if the Shift key is pressed;
in the KeyUp event I would unset the flag as needed.

However, it seems that if I catch the KeyDown, the KeyUp event is not fired,
and/or vice-versa (and let's not even talk about the KeyPressed event !).

In short, I have

<br />
    private void myApp_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<br />
	{<br />
	  MessageBox.Show("KeyDown");<br />
	  e.Handled=false;<br />
	}<br />
	<br />
<br />
    private void myApp_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)<br />
	{<br />
	  MessageBox.Show("KeyUp");<br />
	}<br />


and I see only "KeyDown" message boxes.
Note that the line
e.handled=false;
can be there or not, but the behavior seems to be always the same.

What can I do?

Do I have to dive into
<br />
public class TestMessageFilter: IMessageFilter<br />
{...}<br />

and
<br />
public bool HandleKeys(Keys keyCode)<br />
        {<br />
          bool ret = true;<br />
<br />
          switch(keyCode) {<br />
            case Keys.Shift: ...do stuff...<br />
            default:          ret         = false;          break;<br />
          }<br />
          return ret;<br />
        }<br />


???

Thanks in advance,
F.O.R.
GeneralRe: ? The Key Events Pin
Frank Olorin Rizzi24-Sep-03 12:48
Frank Olorin Rizzi24-Sep-03 12:48 
GeneralInfo for switch statements Pin
Omega50124-Sep-03 11:59
Omega50124-Sep-03 11:59 
GeneralRe: Info for switch statements Pin
Julian Bucknall [MSFT]24-Sep-03 14:55
Julian Bucknall [MSFT]24-Sep-03 14:55 
GeneralRe: Info for switch statements Pin
Omega50124-Sep-03 18:31
Omega50124-Sep-03 18:31 
GeneralRe: Info for switch statements Pin
Julian Bucknall [MSFT]25-Sep-03 4:56
Julian Bucknall [MSFT]25-Sep-03 4:56 
GeneralRe: Info for switch statements Pin
Anonymous25-Sep-03 17:55
Anonymous25-Sep-03 17:55 
GeneralWrite CDs Pin
Ricardo Mendes24-Sep-03 11:33
Ricardo Mendes24-Sep-03 11:33 
GeneralRe: Write CDs Pin
leppie25-Sep-03 7:38
leppie25-Sep-03 7:38 
GeneralRe: Write CDs Pin
Ricardo Mendes25-Sep-03 7:43
Ricardo Mendes25-Sep-03 7:43 
GeneralRe: Write CDs Pin
Jeremy Kimball25-Sep-03 20:17
Jeremy Kimball25-Sep-03 20:17 
GeneralRe: Write CDs Pin
Tomas Petricek25-Sep-03 9:51
Tomas Petricek25-Sep-03 9:51 
GeneralSending GET to a web service Pin
Ed K24-Sep-03 9:34
Ed K24-Sep-03 9:34 
GeneralWindows Form DataGrid Pin
devvvy24-Sep-03 8:21
devvvy24-Sep-03 8:21 
GeneralRe: Windows Form DataGrid Pin
ankita patel24-Sep-03 8:37
ankita patel24-Sep-03 8:37 
GeneralRe: Windows Form DataGrid Pin
devvvy24-Sep-03 8:47
devvvy24-Sep-03 8:47 
GeneralRe: Windows Form DataGrid Pin
ankita patel24-Sep-03 11:48
ankita patel24-Sep-03 11:48 
GeneralRe: Windows Form DataGrid Pin
sumeat24-Sep-03 14:32
sumeat24-Sep-03 14:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.