Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 25-03-2011, 04:36 PM   #1
The Fifth Horseman
FUTURE SCIENCE BASTARD
 
The Fifth Horseman's Avatar


 
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
Default Distunguishing regular and keypad Enter keys in C# forms?

I'm working on a C# application that allows a user to configure a control profile for an emulator. Part of that involves binding keyboard keys to controller buttons, and is done through a clickable "on-screen keyboard" dialog. Today, I decided to add keyboard recognition to the dialog window, so that the user can simply press a key on his keyboard to map it.

It's working, apart from the fact that I don't seem to have any way of telling apart the numpad enter key with the regular enter. This is something I need to fix, but can't find any info on how this could be done.

The current code kludge handling the keyboard input in this part of my application is below:
Code:
        [DllImport("user32.dll")]
        static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);

        private bool IsKeyPressed(Keys key)
        {
            if (Convert.ToInt32(GetAsyncKeyState(key).ToString()) == -32767)
                return true;
            else
                return false;
        }
        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (IsKeyPressed(Keys.LShiftKey)) button55.PerformClick();
            else if (IsKeyPressed(Keys.RShiftKey)) button28.PerformClick();
            else if (IsKeyPressed(Keys.LMenu)) button69.PerformClick();
            else if (IsKeyPressed(Keys.LControlKey))
            {
                if (IsKeyPressed(Keys.RMenu)) button70.PerformClick();
                else button67.PerformClick();
            }
            else if (IsKeyPressed(Keys.RControlKey)) button68.PerformClick();
            else if (IsKeyPressed(Keys.RMenu)) button70.PerformClick();
            else switch (keyData)
                {
                    case Keys.Escape: button1.PerformClick(); break;
                    // there's 90-something lines of the same thing repeated, differentiated only between different Keys enums and buttons.
                    case Keys.Right: button81.PerformClick(); break;

                    default:
                        break;
                }
            
            return true;
            
        }
__________________

"God. Can't you people see I'm trying to commit a crime against science and nature here?"
-- Reed Richards
The Fifth Horseman is offline                         Send a private message to The Fifth Horseman
Reply With Quote
 


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular sgtboat Blah, blah, blah... 4 26-11-2008 03:30 AM
When will regular updates start? Doink Blah, blah, blah... 6 13-12-2007 10:00 AM
How To Make Html/php Forms Read New Lines? Danny252 Programming 2 05-01-2007 08:20 PM
Enter Thevoid's Gallery TheVoid Music, Art, Movies 672 26-06-2006 03:10 PM
Regular Expressions Kon-Tiki Programming 23 26-01-2006 09:58 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 05:34 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.