Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

[Extreme Beginner] Auto send a key every X Minutes

bussdeebussdee Member Posts: 3
First of all i need to say, i am totally new to VB
I finished a german tutorial, how to create a calculator and i think i got the main basics now.

Now my problem:
I like to create my first little tool.
Everything that tool need to do is:
- Press SPACE every X-minutes
- Press a Key (config in form) every X-minutes

another nice function would be, if he scan an area of the screen for a color and when the color change from red to black --> press MOUSE button
(but i think i am still too noob for this)


Do you got any sources of a similar tool,
or do you know any tutorial where i can learn sending keys and scanning for colors?



Any help welcome!
And gratz to this amazing website (found @ google)
i think this will help me a lot learning new languages =)

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    Both can be done. But sending keys is the easiest.

    Use SendKeys and a Timer control.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • bussdeebussdee Member Posts: 3
    Ok, not very helpful, but i got it to work!

    But now i got a big Problem, when i start my tool i am getting a "Runtime Error 70 - Access denied" on my VISTA System. This is my first project @ VB, please talk to me like a child, i am 29 but a big VB-noob! ;)





    Here is some code:

    [code]Private Sub Command1_Click()
    Do
    Sleep 15000
    SendKeys "L"
    Sleep 10000
    ClickLMouseButton "2moons"
    Sleep 3000
    Loop
    End Sub[/code]


    [code]Public Sub ClickLMouseButton(ProgramName As String)

    Dim hWindow As Long
    Dim inputevents(0 To 3) As INPUT_TYPE ' holds information about each mouse event:
    ' left button down/up and right button down/up
    Dim mouseevent As MOUSEINPUT ' temporarily hold mouse input info

    If FnSetForegroundWindow(ProgramName) Then

    ' Load the information needed to imitate pressing the left mouse button.
    With mouseevent
    .dx = 0 ' no horizontal movement
    .dy = 0 ' no vertical movement
    .mouseData = 0 ' not needed
    .dwFlags = MOUSEEVENTF_LEFTDOWN ' right button down
    .time = 0 ' use the default
    .dwExtraInfo = 0 ' not needed
    End With

    ' And copy the structure into the input array's buffer.
    inputevents(0).dwType = INPUT_MOUSE
    CopyMemory inputevents(0).xi(0), mouseevent, Len(mouseevent): Sleep 20

    ' Do the same as above, but for releasing the left mouse button.
    With mouseevent
    .dx = 0 ' no horizontal movement
    .dy = 0 ' no vertical movement
    .mouseData = 0 ' not needed
    .dwFlags = MOUSEEVENTF_LEFTUP ' left button up
    .time = 0 ' use the default
    .dwExtraInfo = 0 ' not needed
    End With

    ' And copy the structure into the input array's buffer.
    inputevents(1).dwType = INPUT_MOUSE
    CopyMemory inputevents(1).xi(0), mouseevent, Len(mouseevent)


    ' Now that all the information for the four input events has been placed
    ' into the array, finally send it into the input stream.
    SendInput 2, inputevents(0), Len(inputevents(0))

    End If
    End Sub[/code]
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Ok, not very helpful, but i got it to work!
    :

    Yeah sorry about that previous response, but I was a bit tired - but I wanted to point you in the right direction.

    : But now i got a big Problem, when i start my tool i am getting a
    : "Runtime Error 70 - Access denied" on my VISTA System. This is my
    : first project @ VB, please talk to me like a child, i am 29 but a
    : big VB-noob! ;)
    :

    You are using VB6 I guess?
    The problem is, that error line could've come from any line - but most likely from CopyMemory.
    Could you step through the code, using the debugger, and pinpoint the line where the error occurs?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • bussdeebussdee Member Posts: 3
    : : Ok, not very helpful, but i got it to work!
    : :
    :
    : Yeah sorry about that previous response, but I was a bit tired - but
    : I wanted to point you in the right direction.
    :
    : : But now i got a big Problem, when i start my tool i am getting a
    : : "Runtime Error 70 - Access denied" on my VISTA System. This is my
    : : first project @ VB, please talk to me like a child, i am 29 but a
    : : big VB-noob! ;)
    : :
    :
    : You are using VB6 I guess?
    : The problem is, that error line could've come from any line - but
    : most likely from CopyMemory.
    : Could you step through the code, using the debugger, and pinpoint
    : the line where the error occurs?
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry


    It`s because SendKeys "L"
    Is there another way to send Mouse Events And Keys without using the Command SendKeys ???
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : It`s because SendKeys "L"
    : Is there another way to send Mouse Events And Keys without using the
    : Command SendKeys ???
    :

    The SendInput should work, but it might have the same restrictions.
    I'm not really familair with Windows Vista's new security measures.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.