How can I make ....?

Well, The main is that I want to make the program alert me what key was press when that key is pressed. How can I make that

Or If there is a good tutorial for starting programming in C#

Thanks




Answer this question

How can I make ....?

  • MausOnMars

    Yeah, it’s working, but your code above it’s a bit wrong, or well it doesn’t work in my PC, I have to put this:

    private void e(object sender, KeyPressEventArgs e)
    {
    String dec = e.KeyChar.ToString();
    MessageBox.Show(dec);
    }

    And it work!!!


  • Paul Clancy

    If you mean a key press across the entire system, then you need to write a system wide hook. Not sure if you can do this in C#, you can in C++.

    If you mean within your app, when your window has the focus, if you create a WinForms app, and then in the designer look at the properties window, there's a lightning flash icon you can click, then you get a list of events you can be notified of in your program. The KeyPress event is called when a key is pressed. You can handle this event, then use MessageBox.Show to show the key that was pressed.

    I would recommend buying a good book, such as Inside C# by Tom Archer. A good book is essential when you start, then you can look for help on the web when you have a solid foundation.



  • Vallari Kamble MSFT

    For some great tutorials go here:

    http://devforums.amd.com/index.php showtopic=453

    Good Luck!


  • Paul Roberts

    Oh Yeah, now it’s working, sorry sorry, you have reason I will buy a book.


  • lpx

    No worries, glad to help :-)



  • Ofer Rosenberg

    That's just turning

    MessageBox.Show(e.KeyChar.ToString());

    ( which was my answer )

    into two steps.

    I totally recommend buying that book, it will give you a solid foundation and a good reference for use later on.



  • MarcDeVegas

    Thanks, that was helpful.

  • PedroCGD

    MessageBox.Show(e.KeyChar); ( if hte messagebox takes a char, I don't think so ) otherwise MessageBox.Show(e.KeyChar.ToString());



  • Brad Peterson MSFT

    It will sound very idiot, but, when I get until this step:

    private void e(object sender, KeyPressEventArgs e)
    {
    MessageBox.Show(e);
    }

    What I have to do, for make the MessaBox.Show() Method alert that any Key was pressed



  • How can I make ....?