Results 1 to 7 of 7

Thread: movement in one time response

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    KL.......
    Posts
    13

    movement in one time response

    I've got a picture. Whenever I press the down key, the picture will go down. The problem is, I want it to response as even though I press and hold the down key, it will only move one step!
    How do I do that?
    Hate not me. Hate your weaknesses

  2. #2
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    ok..

    assuming u mean u want it to keep going even after u lift the key...

    dim keypressed as boolean
    private sub form1_keydown(keycode as integer etc...)
    if keycode = 40 then keypressed = true '40 is down right?
    end sub
    private sub timer1_timer
    if keypressed = true then object1.top = object1.top + 1
    end sub

    this should make it always go down after u rpessed it, if u want ti to stop when u release the key, add

    private sub form1_keyup(same as keydown i think)
    if keycode= 40 then keypressed = false
    end sub
    Don't pay attention to this signature, it's contradictory.

  3. #3
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    keys

    That will probably work in a simple game. But in my experiance if your codeing a complex game that requires the programe to sense someone holding the key down for a long time, its much better to use Direct X 's, Direct Input aspect anything else I tryed useing gave includeing GetAsncKeyState() gave me some occasional weird gliches. Its really easy to use too if you want that code e-mail me [email protected]
    All will fall before the might of the Black Sashi...

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    KL.......
    Posts
    13

    thanks all.

    Thanks all. One more though. Is there a way to no matter how long the keydown is pressed and hold it will only move one step.

    Anyone?
    Hate not me. Hate your weaknesses

  5. #5
    sql_lall
    Guest

    Talking As he said...

    As the other guy said, use the API call:
    GetAsncKeyState()
    then have som boolean switch that changes when GetAsncKeyState() is different from its previous value.

    To check it against a previous value, just use another variable. I.e
    a = GetAsncKeyState(40)
    ......Insert code
    if GetAsncKeyState(40) <> a then BoolSwitch = NOT(BoolSwitch)

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    KL.......
    Posts
    13
    a funny question.....
    no matter how many times I tried the easy method by alkatran, if I would leave out the keyup procedure, the character still does not keep moving! Can someone then post the whole coding for it.
    Hate not me. Hate your weaknesses

  7. #7
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    under form1's keydown:
    If Keycode = vbkeypress then object.top = object.top + 1

    may also be keyascii.. I dunno.. make sure if it is in the sub.
    that (if i did it right, don't have VB installed ATM..) will make it move only once, no matter how long you hold it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width