keypress problems

Discussion in 'Programming General' started by Reximus, Dec 5, 2007.

keypress problems
  1. Unread #1 - Dec 5, 2007 at 9:10 AM
  2. Reximus
    Referrals:
    0

    Reximus Guest

    keypress problems

    trying to make a programthat will press up down left and right for random intervals at random intervals

    the random interval isnt the problem but holding down the keys for a random time is

    only way i know of sending the keys is by using sendkeys
    but this doesnt work in random intervals

    i tried something like this but it doesnt work:

    for num = 1 to rnd ' this is my random number
    sendkeys.send("{UP"}
    next num

    this doesnt have the desired effect
    so i was wondering if its possible to use keypress
    done some googling and found nothing
    can anyone point me in the right direction?
     
  3. Unread #2 - Dec 6, 2007 at 12:22 AM
  4. skate4lifee
    Joined:
    Jul 22, 2007
    Posts:
    108
    Referrals:
    1
    Sythe Gold:
    0

    skate4lifee Active Member

    keypress problems

    try using getasynckeystate, sendkeys is used for actually sending the key for example sendkeys would be used in an auto typer to send what you have typed

    e.g.
    Code:
    sendkeys.send(textbox1.text)
    the msdn website is a nice reference:
    http://msdn2.microsoft.com/en-us/library/ms646293.aspx
     
  5. Unread #3 - Dec 6, 2007 at 12:32 PM
  6. Reximus
    Referrals:
    0

    Reximus Guest

    keypress problems

    very handy for noticing if the button is manually pressed but i want my program to press the button and hold it down, the reference did show me Sendinput but thats just the same effect as sendkeys
    (instead of pressing and holding it just presses multiple times)
     
  7. Unread #4 - Dec 6, 2007 at 7:37 PM
  8. skate4lifee
    Joined:
    Jul 22, 2007
    Posts:
    108
    Referrals:
    1
    Sythe Gold:
    0

    skate4lifee Active Member

    keypress problems

    may i ask what this is for?

    instead of the program pressing the button you can make a timer that does the same thing the button would do if pressed. so for the timer you can write whatever you would like to happen inside of the timer. lets use a simple messagebox for example, so first you would add a timer and in the timer add the code

    Code:
    messagebox.show("test")
    timer1.interval = textbox1.text * 1000
    so the interval of the timer will depend on what number you set for the textbox otherwise if you don't want to use a textbox just put in a number.

    then for this next step you can use either a button or getasynckeystate.

    for a button all you would do is this, see below:

    button1:
    Code:
    timer1.enabled = true
    button2 code:
    Code:
    timer1.enabled = false
    now if you wanted to use getasynckeystate you would first need to declare the getasynckeystate function, see below:

    Code:
    Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short
    you can then make another timer to start up at as the form loads by using the formload property and adding this code, see below:

    Code:
    timer2.enabled = true
    then for the code of timer2 you can say this, see below:

    Code:
    if getasynckeystate(keys.F1) then
    timer1.enabled = true
    keep in mind that timer1 is told to open up a messagebox every second.
    now to turn off timer one we will go back to the timer2 code and add this, see below:

    Code:
    if getasynckeystate(keys.F1) then
    timer1.enabled = false
    if i didn't answer your question maybe try rephrasing it or telling me what you plan on making and i might be able to help you out a little better.
     
  9. Unread #5 - Dec 7, 2007 at 8:48 AM
  10. Reximus
    Referrals:
    0

    Reximus Guest

    keypress problems

    ok if you play runescape im trying to make it automatically move the camera for x amount of time in a certain direction (to stop you auto logging out)

    getasynckeystate is of no use as that only tells me if i have pressed the button

    i need something that will press (and hold) the button down
    sending the left key multiple times doesnt work

    sending a keydown or something would be great but i cant seem to find anything that is capable of that
     
  11. Unread #6 - Dec 8, 2007 at 12:41 AM
  12. skate4lifee
    Joined:
    Jul 22, 2007
    Posts:
    108
    Referrals:
    1
    Sythe Gold:
    0

    skate4lifee Active Member

    keypress problems

    by using the keydown property of a button you can use sendkeys

    Code:
    button1_keydown
    sendkeys.send = keys.enter
    end sub
    something like that, i just recently reinstalled windows and haven't had a chance to install visual basic. once i do i'll see what i can do to help you out a little more by maybe making an example project.
     
< use scanner barcode in VB 6.0 | VB 6 link >

Users viewing this thread
1 guest


 
 
Adblock breaks this site