d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C# Arrow Key Press > Need Your Help!
Add Reply New Topic New Poll
Member
Posts: 2,923
Joined: Oct 23 2009
Gold: 0.00
Jul 6 2012 12:59am
So basically. I have a bunch of images that are displayed when i press the button labelled 'Next'
And what i want is, when the right arrow key is pressed, for it to do the same as the button (click it)

is this possible
and tell me if i didnt make any sense

thank you all :)
Member
Posts: 827
Joined: Jan 16 2012
Gold: 0.00
Warn: 10%
Jul 9 2012 03:13pm
Member
Posts: 2,303
Joined: Oct 11 2007
Gold: 0.00
Jul 10 2012 06:23pm
it is possible.. you are using forms right?

// Create a new event for the keydown action.
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormName_KeyDown);
// Add code to it
private void FormName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
{
// Your code here
}
}
Member
Posts: 17,028
Joined: Jan 18 2005
Gold: 15,778.00
Aug 19 2012 10:55pm
Quote (Eleven11 @ Jul 10 2012 06:23pm)
it is possible.. you are using forms right?

// Create a new event for the keydown action.
this.KeyDown += newSystem.Windows.Forms.KeyEventHandler(this.FormName_KeyDown);
// Add code to it
private void FormName_KeyDown(objectsender, KeyEventArgse)
{
if(e.KeyCode == Keys.Left)
            {
            // Your code here
            }
}


Also note that this code will execute every update while the key is down. It would actually be more efficient to change the state of the images from not displaying to displaying when the key state changes from KeyUp to KeyDown and then change the state back again on KeyUp. It really doesn't matter that much since you aren't going to bottleneck here but it's good practice to try and write code that is the most obviously optimized whenever you can. Just my 2 cents.

This post was edited by Thrasher66099 on Aug 19 2012 10:56pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll