Jump to content

Switcher


Go to solution Solved by SOLVE-SMART,

Recommended Posts

Hey, 

doing small stuff in AutoIt just for training and feeling nice with it. 

 

Have already script builded for my needes,

but asking you guys for help with Turn ON/OFF Func.

 

 

#include <misc.au3>
HotKeySet("1", "start")
HotKeySet("2", "stop")

Func start();
    MouseDown("middle")
EndFunc

Func stop();
    MouseUp("middle")
EndFunc

 

Looking for solution to switch Mouse down/up with 1 key 

 

Link to comment
Share on other sites

Hi @SevenScript,

I guess you are looking for a toggle function. Please search the forum for toggle and you will get examples that are similar to your question.

I don't have enough time at the moment to script a quick script as an example, because I am in rush. Maybe later today.

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

and when tray no needed this just with HotKey

#include <misc.au3>

Local $Enabled, $SleepTime
Enabled()

While 1
    Sleep($SleepTime)
WEnd

Func start();
    ;MouseDown("middle")
    MouseWheel("down")
EndFunc

Func stop();
    ;MouseUp("middle")
    MouseWheel("up")
EndFunc

Func Enabled()
    if $Enabled = True Then
        $Enabled = False
        $SleepTime = 1000
        HotKeySet("1")
        HotKeySet("2")
    Else
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
        HotKeySet("1", "start")
        HotKeySet("2", "stop")
    EndIf
ConsoleWrite("$Enabled=" & $Enabled & @CRLF)

EndFunc

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

  • Solution

To be honest @ioa747,

I was actually thinking about such toggle function:

HotKeySet('{ESC}', '_Exit')
HotKeySet('1', '_ToggleMouse')

Global $bIsDown = False

Func _Exit()
    Exit
EndFunc

Func _ToggleMouse()
    $bIsDown = Not $bIsDown

    If $bIsDown Then
        MouseDown('middle')

        Return
    EndIf

    MouseUp('middle')
EndFunc

While True
    Sleep(200)
WEnd

Simply press "1" to do the mouse down ("middle" key) action and press "1" again for the mouse up action (and again and again 😅).
I think this is exactly what @SevenScript wanted to know, am I right?

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

@SOLVE-SMART  You have right !

my eye  stayed to

On 1/23/2023 at 6:10 AM, SevenScript said:

but asking you guys for help with Turn ON/OFF Func

than in

On 1/23/2023 at 6:10 AM, SevenScript said:

Looking for solution to switch Mouse down/up with 1 key 

 

Thanks for suggestions.  :)

I know that I know nothing

Link to comment
Share on other sites

You're welcome @ioa747 🤝 .

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • 2 weeks later...
On 1/23/2023 at 9:55 AM, ioa747 said:

and when tray no needed this just with HotKey

#include <misc.au3>

Local $Enabled, $SleepTime
Enabled()

While 1
    Sleep($SleepTime)
WEnd

Func start();
    ;MouseDown("middle")
    MouseWheel("down")
EndFunc

Func stop();
    ;MouseUp("middle")
    MouseWheel("up")
EndFunc

Func Enabled()
    if $Enabled = True Then
        $Enabled = False
        $SleepTime = 1000
        HotKeySet("1")
        HotKeySet("2")
    Else
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
        HotKeySet("1", "start")
        HotKeySet("2", "stop")
    EndIf
ConsoleWrite("$Enabled=" & $Enabled & @CRLF)

EndFunc

 

 

Hello @ioa747

 

I wonder how could i use your "Enabled" option with IsPressed function

 

#include <misc.au3>

Local $Enabled, $SleepTime
Enabled()

While 1
    Sleep($SleepTime)
WEnd

Func start();
    
    While 1
        Sleep(10)
    If _IsPressed("90") Then
        sleep(50)
        Send("Its")
        sleep(200)
        Send("a simply")
        sleep(200)
        Send("text")
        sleep(150)
    EndIf
WEnd

EndFunc


Func Enabled()
    if $Enabled = True Then
        $Enabled = False
        $SleepTime = 1000
        HotKeySet("1")
    Else
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
        HotKeySet("1", "start")
    EndIf


EndFunc

 

After running that script IsPressed is no active untill i press "1"

But it doesn't deactivate after use "1" or "ESC"

 

Could you please explain me how it works?

 

Link to comment
Share on other sites

 

While 1
        Sleep(10)
        If $Enabled = True Then
            If _IsPressed("90") Then ; 90 NUM LOCK key
                Sleep(50)
                Send("Its")
                Sleep(200)
                Send("a simply")
                Sleep(200)
                Send("text")
                Sleep(150)
            EndIf
        EndIf
    WEnd

 

I know that I know nothing

Link to comment
Share on other sites

with a second review, as long as it is in the HotKeySet function

Func start() ;
    While $Enabled
        Sleep(10)
        If _IsPressed("90") Then     ; 90 NUM LOCK key
            Sleep(50)
            Send("Its")
            Sleep(200)
            Send("a simply")
            Sleep(200)
            Send("text")
            Sleep(150)
        EndIf
    WEnd
EndFunc   ;==>start

 

I know that I know nothing

Link to comment
Share on other sites

and this make pause status more visible

Func Enabled()
    If $Enabled = True Then
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Red.ico")
        $Enabled = False
        $SleepTime = 1000
        HotKeySet("1")
    Else
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
        HotKeySet("1", "start")
    EndIf
EndFunc   ;==>Enabled

 

I know that I know nothing

Link to comment
Share on other sites

  • 3 weeks later...
On 2/6/2023 at 11:11 AM, ioa747 said:

 

While 1
        Sleep(10)
        If $Enabled = True Then
            If _IsPressed("90") Then ; 90 NUM LOCK key
                Sleep(50)
                Send("Its")
                Sleep(200)
                Send("a simply")
                Sleep(200)
                Send("text")
                Sleep(150)
            EndIf
        EndIf
    WEnd

 

Hello \o 

About that option, 
How could i start script with $Enable = False

 

So it's no active until i press Hotkey ESC Enable

Link to comment
Share on other sites

On 2/6/2023 at 11:57 AM, SevenScript said:

But it doesn't deactivate after use "1" or "ESC"

That was the point of stopping with Esc, that's what i understood

try this version with one switch If it works for you  ESC = on/off

Func Enabled()
    If $Enabled = True Then
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Red.ico")
        $Enabled = False
        $SleepTime = 1000
;~      HotKeySet("1")
    Else
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
;~      HotKeySet("1", "start")
        start()
    EndIf
EndFunc   ;==>Enabled

 

I know that I know nothing

Link to comment
Share on other sites

16 minutes ago, ioa747 said:

That was the point of stopping with Esc, that's what i understood

try this version with one switch If it works for you  ESC = on/off

Func Enabled()
    If $Enabled = True Then
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Red.ico")
        $Enabled = False
        $SleepTime = 1000
;~      HotKeySet("1")
    Else
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
;~      HotKeySet("1", "start")
        start()
    EndIf
EndFunc   ;==>Enabled

 

 

Hello, 

Thank you for answer. 

 

Your idea works properly and you gave me code which improved my au3 understanding 

 

Local     $Enabled, $SleepTime

Enabled()

Func Enabled()
    If $Enabled = True Then
        $Enabled = False
        $SleepTime = 1000
    Else
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
    EndIf
EndFunc   ;==>Enabled



While 1
        Sleep(10)
        If $Enabled = True Then
            If _IsPressed("90") Then ; 90 NUM LOCK key
                Sleep(50)
                Send("Its")
                Sleep(200)
                Send("a simply")
                Sleep(200)
                Send("text")
                Sleep(150)
            EndIf
        EndIf
    WEnd

 

That option works great but wonder how could i start script with Enable = False, 

 

I mean after script start i can press NumLock from beggining and it results "Its a simply text".

What have to do to get that option working after first ESC

Edited by SevenScript
Link to comment
Share on other sites

 

try it

This is the correct order,  the functions go down

#include <misc.au3>

Local $Enabled, $SleepTime
Enabled()

;************************************************
While 1
    Sleep($SleepTime)
WEnd
;************************************************

Exit

;----------------------------------------------------------------------------------------
Func start() ;
    While $Enabled
        Sleep(10)
        If _IsPressed("90") Then     ; 90 NUM LOCK key
;~          ConsoleWrite(":")

            Sleep(50)
            Send("Its")
            Sleep(200)
            Send("a simply")
            Sleep(200)
            Send("text")
            Sleep(150)


        EndIf
    WEnd
EndFunc   ;==>start
;----------------------------------------------------------------------------------------
Func Enabled()
    If $Enabled = True Then
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Red.ico")
        $Enabled = False
        $SleepTime = 1000
    Else
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
        start()
    EndIf
EndFunc   ;==>Enabled

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Local     $Enabled, $SleepTime

Enabled()

Func Enabled()
    If $Enabled = True Then
        $Enabled = False
        $SleepTime = 1000
    Else
        $Enabled = True
        $SleepTime = 10
        HotKeySet("{ESC}", "Enabled")
    EndIf
EndFunc   ;==>Enabled



While 1
        Sleep(10)
        If $Enabled = True Then
            If _IsPressed("90") Then ; 90 NUM LOCK key
                Sleep(50)
                Send("Its")
                Sleep(200)
                Send("a simply")
                Sleep(200)
                Send("text")
                Sleep(150)
            EndIf
        EndIf
    WEnd

 

That's my favourite option

There is no Start function, just Enabled. 

And when $Enabled = True then IsPressed is active.

--------------------------------------------------------------------------------

So double click on script and press NumLock = It's a simply text. 

---------------------------------------------------------------------------------

What i try to achive: 

 

Double click on script

ESC to make $Enable = True

and then NumLock = It's a simply qestion

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...