Quick question

12/18/2013 23:06 hunterman01#1
Hey what's up everyone,


I'm stuck on something so simple it blows my mind.

Okay, what im trying to do is when you press enter on a form it does something

For instance

Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                    // do something
            }
        }
I know several ways of going about this but like i said very simple just caught up for some reason.

Any ideas?
12/18/2013 23:40 SteveRambo#2
I don't see a question anywhere :confused:
12/18/2013 23:45 hunterman01#3
Quote:
Originally Posted by SteveRambo View Post
I don't see a question anywhere :confused:
For a second, i thought you were just some noob who had no idea what i was talking about. Then i looked at your profile, so i will make it a little bit clearer.

That little bit of code actually does nothing what so ever. Whenever you press enter, nothing happens. Which is strange.
12/18/2013 23:49 SteveRambo#4
Quote:
Originally Posted by hunterman01 View Post
For a second, i thought you were just some noob who had no idea what i was talking about. Then i looked at your profile, so i will make it a little bit clearer.

That little bit of code actually does nothing what so ever. Whenever you press enter, nothing happens. Which is strange.
What do you want it to do? I mean, there's obviously no code inside the if statement ... Or am I misreading something?
12/19/2013 00:29 Aceking#5
The enter button is considered a special input key, for example many buttons will use enter as a way to trigger the button click, and as such the form excludes enter from being caught in a key event.

Use:

Code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                // Enter pressed
                //doSomething();
                button1.Text = "lllll";
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
12/19/2013 00:58 hunterman01#6
Quote:
Originally Posted by SteveRambo View Post
What do you want it to do? I mean, there's obviously no code inside the if statement ... Or am I misreading something?
Let me elaborate a little bit more, Basically when someone press's enter it will launch another application for example
Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                System.Diagnostics.Process.Start("test.exe");
            }
        }
Quote:
Originally Posted by Aceking View Post
The enter button is considered a special input key, for example many buttons will use enter as a way to trigger the button click, and as such the form excludes enter from being caught in a key event.

Use:

Code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                // Enter pressed
                //doSomething();
                button1.Text = "lllll";
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

*EDIT*

That worked, thanks bro.
12/19/2013 00:59 SteveRambo#7
Quote:
Originally Posted by Aceking View Post
The enter button is considered a special input key, for example many buttons will use enter as a way to trigger the button click, and as such the form excludes enter from being caught in a key event.

Use:

Code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                // Enter pressed
                //doSomething();
                button1.Text = "lllll";
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
What? No. The reason that pressing the Enter key doesn't trigger the form's KeyDown/KeyUp/KeyPressed events is most likely because some other control is taking the focus away from the form and whenever a key is pressed, the event it sent to that control instead of the form itself. In that case, you just need to handle the specific control's events instead of the form's.
12/19/2013 01:04 hunterman01#8
Quote:
Originally Posted by SteveRambo View Post
What? No. The reason that pressing the Enter key doesn't trigger the form's KeyDown/KeyUp/KeyPressed events is most likely because some other control is taking the focus away from the form and whenever a key is pressed, the event it sent to that control instead of the form itself. In that case, you just need to handle the specific control's events instead of the form's.
You and him were both right, i had something else going on.
12/19/2013 01:13 Super Aids#9
Wrong section anyways.
12/19/2013 03:24 Y u k i#10
Quote:
Originally Posted by Super Aids View Post
Wrong section anyways.
The coding section on epvp is mostly german. Good luck getting an answer over there.
12/19/2013 03:36 .Light#11
Quote:
Originally Posted by Super Aids View Post
Wrong section anyways.
Agreeing with Yuki. Also this question out of context doesn't have anything to do with a CO Private Server BUT in context it does (;
12/19/2013 03:59 Spirited#12
Alright. If that's the case, I'll look out for English posts in that section. The moderator of that section is also English speaking, I believe. But yes, this is completely unrelated to Conquer Online, so I will be moving this with a 24 hour redirect. Also, since the thread has been successfully resolved, I suppose it can be closed. Cheers.