locked
keypress , keyup, keydown RRS feed

  • Question

  • K, I have been examining the keypress event, but don't know how to use it.

    How can I possibly use it, to let's say, move a picturebox up whilst it's held down

    I know I need to loop, so here is my code

    do(keydown(vk_up)
    {
    for(i=0 ,i > 10000 ,i++)
    {
    picturebox1.Location = (i, 20)
    }
    while(!keyup(vk_up)

    is there some way to do a code like that?

    Thursday, February 5, 2009 9:43 PM

Answers

  • As Hans has indicated, Windows is event-driven. Interactive programs need to be event-driven.

    If you do things the way Windows usually uses the keyboard to move a window, then you need to have a way to first put the window into a move mode. Then when a key is pressed that is supposed to do something, then you do that and finish processing that key. Your message loop is the loop that will wait for more keys and other events. You need to learn about Windows programming to know how to use message loops properly. If you use MFC or the CLR then you will use the message loop they provide.

    Your requirement is easy to do if you understand how Windows programming works.
    Sam Hobbs; see my SimpleSamples.Info
    Friday, February 6, 2009 7:17 PM

All replies

  • Your code isn't close by a mile.  You'll need to visit your local library and check out some books on .NET Windows Forms programming.  It is very different from the traditional C/C++ coding style you are used to.
    Hans Passant.
    Friday, February 6, 2009 2:38 AM
  • As Hans has indicated, Windows is event-driven. Interactive programs need to be event-driven.

    If you do things the way Windows usually uses the keyboard to move a window, then you need to have a way to first put the window into a move mode. Then when a key is pressed that is supposed to do something, then you do that and finish processing that key. Your message loop is the loop that will wait for more keys and other events. You need to learn about Windows programming to know how to use message loops properly. If you use MFC or the CLR then you will use the message loop they provide.

    Your requirement is easy to do if you understand how Windows programming works.
    Sam Hobbs; see my SimpleSamples.Info
    Friday, February 6, 2009 7:17 PM