Jump to content

Recommended Posts

Posted (edited)

So I have 2 functions running in this script, one is CTRL which runs continuously without any conditions. Other is ESC function which wait for color pixels to appear on the screen.

Here is the problem, whenever ESC function is activated, it doesnt send ESC command to a computer but it sends CTRL+ESC which results in windows 10 shortcut commands 

Windows 10 - Open Start Menu

So I decide to declare variable inside my script which is $noctrl

so whenever ESC function sees a pixel on a screen it will set $noctrl to 1 which will deactivate CTRL function automatically.

But I dont know why my script isn't working, It seems that everything is correct.

Here is my script

HotKeySet("{END}", "End")
HotKeySet("{HOME}", "Start")

Global $noctrl = 0 ;<<<<<<<<<<<Set $noctrl to zero

While 1
    Sleep(100)
WEnd

Func Start()
    While 1
        CTRL()
        ESC()
    WEnd
EndFunc   ;==>Start

Func ESC()
    If PixelSearch(712, 137, 906, 244, 0xF70000) & $noctrl = 0 Then ;<<<<<<<<<<<If $noctrl is set to zero and pixel is spotted on the screen then execute the function
        $noctrl = 1 ;<<<<<<<<<<<Set $noctrl to one to deactivate CTRL function
        Sleep(1000)
        Send("{LCTRL UP}") ;<<<<<<<<<<<To avoid LCTRL that is still pressed down.
        Sleep(1000)
        Send("{ESC DOWN}")
        Sleep(100)
        Send("{ESC UP}")
        Sleep(3000)

        $noctrl = 0 ;<<<<<<<<<<<Set $noctrl to zero to activate the CTRL function again
    EndIf
EndFunc   ;==>ESC

Func CTRL()
    If $noctrl = 0 Then  ;<<<<<<<<<<< This function WILL NOT execute when function ESC is running. Because while it's running $noctrl is set to 1.
        Send("{LCTRL DOWN}")
        Sleep(Random(10, 100, 1))
        Send("{LCTRL UP}")
    EndIf
EndFunc   ;==>CTRL

Func End()
    Exit 0
EndFunc   ;==>End

I dont know which part of this I got wrong because it seems like function ESC is dead and no longer detecting color.

Edited by Melba23
Added code tags
  • Moderators
Posted

plankton,

When you post code in future please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Thanks in advance for your cooperation.

As to your code you do not need the $noctrl flag - AutoIt functions run consecutively and CTRL will not start before ESC ends - so there must be another problem. I suspect that you have a "sticky" CTRL key and this Wiki page might be helpful.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted
20 minutes ago, Melba23 said:

plankton,

When you post code in future please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Thanks in advance for your cooperation.

 As to your code you do not need the $noctrl flag - AutoIt functions run consecutively and CTRL will not start before ESC ends - so there must be another problem. I suspect that you have a "sticky" CTRL key and this Wiki page might be helpful.

 M23

  

Hi, Melba23, I think you just nailed it. I didnt think of this "sticky" key before and I have wasted my time re-writing my code for several hours. I think I will change my keyboard layout and avoid using shift, ctrl and alt keys from now on.

 

Thank you.

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
×
×
  • Create New...