d2jsp
Gaming and Trading Community
Gaming and Trading Community
Hourly Raffle
Ladder Slasher
Trade Finder
Photo Gallery
Forum Gold FAQ
Instant Messenger
Help and Rules
Live Streams
Account RecoveryResend Validation Email
Hello, GuestLog InRegister
d2jsp Forums > Programmer's Haven > C/C++/C# > C# Arrow Key Press > Need Your Help!

Add ReplyNew TopicNew Poll
Page 1 of 1
xanderburgess
#1 Jul 6 2012 12:59am
Group: Members
Posts: 2,916
Joined: Oct 23 2009
Gold: 0.00
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 :)
StormHasHe
#2 Jul 9 2012 03:13pm
Group: Members
Posts: 795
Joined: Jan 16 2012
Gold: 0.00
Eleven11
#3 Jul 10 2012 06:23pm
Group: Members
Posts: 1,886
Joined: Oct 11 2007
Gold: 25.00
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
}
}
Thrasher66099
#4 Aug 19 2012 10:55pm
Group: Members
Posts: 14,561
Joined: Jan 18 2005
Gold: 38,788.00
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 C/C++/C# Topic List
Page 1 of 1