0

Is there a way to accept keystrokes through c# in a console app? Basically I want to apply macros/the f-keys to my program, thanks.

2
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by InfiNate
0

Yes, you need to subscribe your form to a key event.

Something like:

this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.KeyUpEvent);

public void KeyUpEvent(object sender, KeyEventArgs e){

//Code here to handle specific keys
}

Can alternative use KeyDown or KeyPress events instead of Keyup.

0

It's not a form though, it's a console app, any way to do it through a console app?

0

Ok but won't that require the user to type in "f9" or whatever then hit enter? I want to bypass that like you would in a form.

1

I've never used it, but console.readkey() might be what you are looking for.

Votes + Comments
bumping your rep since the OP has zero rep power
0

After doing some research on using console.readkey(), it turns out this is exactly what I needed! Thank god .net 1.1 isn't the standard anymore as things like this were very limited back then. Thanks again!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.