Jump to content

Recommended Posts

Posted (edited)
#include <Misc.au3>

Global $timer = 0
Global $timer2 = 0
Global $diff = 0
Global $diff2 = 0

While 1

    If _IsPressed("31") Then
        Do
            Send("{SPACE}")
            if $timer = 0 Then
                Send("f")
                $timer = TimerInit()

            $diff = TimerDiff($timer)

            ElseIf $diff >= 30 Then
                $timer = 0
            Endif

            if $timer2 = 0 Then
                Send("e")
                $timer2 = TimerInit()

            $diff2 = TimerDiff($timer2)

            ElseIf $diff2 >= 28 Then
                $timer2 = 0
            Endif

        Until not _IsPressed("31")
    EndIf

WEnd

 

Working on holding the vk32 key down and it only triggering the initial 2 actions, then waiting for their respective timers to meet the desired wait time to trigger them again.

 

Right now, it's only firing the first and then it just stops. The key no longer does anything. So I tried moving the diff's to the top as Global... just been reading and tweaking for a while.

 

Any ideas?

Edited by Xilibre
Link to post
Share on other sites
Posted (edited)

Tried it a little differently... still failing.

#include <Misc.au3>
_Singleton(@ScriptName)

While 1
    hotkeyset("{END}","EndProgram")

    If _IsPressed("32") Then

        $timer = TimerInit()
        $timer2 = TimerInit()
        $timer3 = TimerInit()
        $InitialUse = false
        $InitialUse2  = false

        Do
            if $InitialUse = False Then
                Send("f")
                $InitialUse = True
            EndIf

            Send("{SPACE}")

            if TimerDiff($timer) > 30000 Then
                Send("f")
                $timer = TimerInit()
            EndIf

            if $InitialUse2 = False Then
                Send("e")
                $InitialUse2 = True
            EndIf

            Send("{SPACE}")

            if TimerDiff($timer2) > 30000 Then
                Send("e")
                $timer2 = TimerInit()
            EndIf

            Sleep(200)

            if TimerDiff($timer3) > 10000 Then
                $InitialUse = False
                $InitialUse2 = False
                $timer3 = TimerInit()
            EndIf

        Until not _IsPressed("32")

    EndIf

WEnd

;Exit program
Func EndProgram()
    Exit
EndFunc

 

Edited by Xilibre
Link to post
Share on other sites
Posted (edited)
12 hours ago, Xilibre said:

lol, well, even if no one knows the answer to this question

#include <WinAPISys.au3> ; for _WinAPI_Keybd_Event(), _WinAPI_GetKeyState()
#include <WinAPIvkeysConstants.au3> ; for $VK_*

#Region examples for Shortcut Guide ; https://docs.microsoft.com/en-us/windows/powertoys/
_Send_VirtualKey($VK_LWIN, Default, 2000) ; VK_LWIN ; press, hold 2000 ms., release key
Sleep(1000)
#EndRegion examples for Shortcut Guide ; https://docs.microsoft.com/en-us/windows/powertoys/

_Send_VirtualKey($VK_LWIN, 1) ; VK_LWIN  ;  key down    ; Left Windows key (Natural keyboard)
_Send_VirtualKey($VK_1)       ; 1 key    ;  send key 1  ; run first icon in the Taskbar
_Send_VirtualKey($VK_LWIN, 2) ; VK_LWIN  ;  key up      ; Left Windows key (Natural keyboard)
Sleep(1000)
_Send_VirtualKey($VK_LWIN) ; VK_LWIN ; load Start menu ; Left Windows key (Natural keyboard)
Sleep(1000)
SetNumLock() ; look at the keyboard light
ToolTip("")


Func _Send_VirtualKey($iVkey, $bPressDownUp = Default, $iSleep = Default) ; $iSleep in ms.
    If Not IsInt($iVkey) Then Return ; https://www.autoitscript.com/forum/index.php?showtopic=205790&view=findpost&p=1481401
    $bPressDownUp = Int($bPressDownUp) ; https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
    Switch $bPressDownUp ;
        Case 1, 2, 3
            ; all good ; 1=down ; 2=up ; 3=1+2
        Case Else
            $bPressDownUp = BitOR(1, 2)
    EndSwitch
    $iSleep = Int($iSleep) ; Default = 0
    If BitAND($bPressDownUp, 1) Then _WinAPI_Keybd_Event($iVkey, 0)
    If $iSleep Then Sleep($iSleep)
    If BitAND($bPressDownUp, 2) Then _WinAPI_Keybd_Event($iVkey, $KEYEVENTF_KEYUP)
EndFunc   ;==>_Send_VirtualKey

Func SetNumLock($bState = Default) ; $bState: True=ON , False=OFF, Default=toggle
    If $bState <> Default Then ; example from https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-keybd_event
        Local $iKeyState = _WinAPI_GetKeyState($VK_NUMLOCK) ; 0 or 1 ; false or true
        If Int($bState) = $iKeyState Then Return SetError(0, $iKeyState, 1)
    EndIf
    _WinAPI_Keybd_Event($VK_NUMLOCK, $KEYEVENTF_EXTENDEDKEY)
    _WinAPI_Keybd_Event($VK_NUMLOCK, $KEYEVENTF_EXTENDEDKEY + $KEYEVENTF_KEYUP)
EndFunc   ;==>SetNumLock

so, ..... friendly AND gave you the right path in your quest. The rest you'll have to research on your own ;) 

Edited by argumentum
better code example
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...