C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,153 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,664 people online right now. Registration is fast and FREE... Join Now!




Keyboardfilter Question

 

Keyboardfilter Question

daveofgv

2 Aug, 2009 - 04:37 AM
Post #1

New D.I.C Head
*

Joined: 6 Nov, 2008
Posts: 7

Hello everyone,

I have a quick question that I am sure will be answered very quickly........

I am using:
CODE

   private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            KeyboardFilter filter = new KeyboardFilter(new Keys[] { Keys.LWin, Keys.RWin, Keys.Escape | Keys.Control });
        }


for a checkbox. It works great to disable control + escape, however, I can not seem to cancel the method when the user unchecks the checkbox.

Does anyone know how I can make the ctrl+esc work again when the user unchecks the box?

thanks

daveofgv

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 3)

SixOfEleven

RE: Keyboardfilter Question

2 Aug, 2009 - 05:47 AM
Post #2

lives.ToCode();
Group Icon

Joined: 18 Oct, 2008
Posts: 3,072



Thanked: 171 times
Dream Kudos: 825
Expert In: C, C#, XNA, Game Programming, Programming Concepts

My Contributions
QUOTE(daveofgv @ 2 Aug, 2009 - 06:37 AM) *

Hello everyone,

I have a quick question that I am sure will be answered very quickly........

I am using:
CODE

   private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            KeyboardFilter filter = new KeyboardFilter(new Keys[] { Keys.LWin, Keys.RWin, Keys.Escape | Keys.Control });
        }


for a checkbox. It works great to disable control + escape, however, I can not seem to cancel the method when the user unchecks the checkbox.

Does anyone know how I can make the ctrl+esc work again when the user unchecks the box?

thanks

daveofgv


You could try and use the Checked property of the check box to set the filter.

CODE

private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
    KeyboardFilter filter;

    if (checkBox5.Checked)
        filter = new KeyboardFilter(new Keys[] { Keys.LWin, Keys.RWin, Keys.Escape | Keys.Control });
    else
        filter = new KeyboardFilter(new Keys[] { Keys.LWin, Keys.RWin });
}

User is online!Profile CardPM
+Quote Post

daveofgv

RE: Keyboardfilter Question

2 Aug, 2009 - 06:22 AM
Post #3

New D.I.C Head
*

Joined: 6 Nov, 2008
Posts: 7

CODE

{
    KeyboardFilter filter;

    if (checkBox5.Checked)
        filter = new KeyboardFilter(new Keys[] { Keys.LWin, Keys.RWin, Keys.Escape | Keys.Control });
    else
        filter = new KeyboardFilter(new Keys[] { Keys.LWin, Keys.RWin });
}


This does the samething. When I check the box the keys control+escape are blocked, however, when I uncheck the box the keys are still disabled.

Should I being using something other then "checkBox1_CheckedChanged"?
User is offlineProfile CardPM
+Quote Post

SixOfEleven

RE: Keyboardfilter Question

2 Aug, 2009 - 07:43 AM
Post #4

lives.ToCode();
Group Icon

Joined: 18 Oct, 2008
Posts: 3,072



Thanked: 171 times
Dream Kudos: 825
Expert In: C, C#, XNA, Game Programming, Programming Concepts

My Contributions
The event handler you have chosen is the right event handler. For example I had a check box and a label on my form and I had this code in the event handler for the CheckChanged event.

CODE

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if (checkBox1.Checked)
        label1.Text = "Checked";
    else
        label1.Text = "Unchecked";
}


The text in the label switched between the two values as it should according to the state of the Checked property so the programming logic is right. So it looks like the problem with the keys still being blocked might be with the KeyboardFilter itself.

I did have one thought on what might be causing your problem. For your keyboard filter you might not want to create it inside the event handler. You might want to make it a class wide variable instead.

CODE

KeyboardFilter filter;

private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
    if (checkBox5.Checked)
    {
        // Set the filter
    }
    else
    {
        // Reset the filter
    }
}


This post has been edited by SixOfEleven: 2 Aug, 2009 - 07:43 AM
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 05:07PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month