Sign in to follow this  
Followers 0
FrequentUser

Help with a disabling function.

16 posts in this topic

 
While True
$color = PixelGetColor(@DesktopWidth / 2, @DesktopHeight / 2)
If $color = 16711680 Or $color = 16646144 Then
MouseClick ("middle")
Sleep(10)
EndIf
Wend
 
This is my current script, however I'd like to make it where if I press the number "4" It'll activate the script (have it active) and if I press "5" it'll deactivate it. I don't want a temporary pause of some sort, I want it to physically have a start/stop function. I've tried looking at the hotkeypress examples of pausing the script however it does not work. I'm using this script on a full screen application hence I need it to disable/enable via those hotkeys, 4/5
 
Could someone help me out with this code ;/ kinda new to all this.
 
Thanks.

Share this post


Link to post
Share on other sites



bump

Share this post


Link to post
Share on other sites

FrequentUser,

Welcome to the AutoIt forum. :)

But please do not bump your own threads within 24 hours. Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. So be patient. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

This should do it:

HotKeySet("{5}", "_Exit")
HotKeySet("{4}", "_Start")
Global $iBreak = 0

Func _Start()
    While 1
        If $iBreak = 1 Then
            $iBreak = 0
            ExitLoop
        EndIf
        Sleep(3000)
        ConsoleWrite("Loop" & @CRLF)
    WEnd
EndFunc   ;==>_Start

Func _Exit()
    $iBreak = 1
    ConsoleWrite("Break" & @CRLF)
EndFunc   ;==>_Exit

While 1
    Sleep(1000)
WEnd

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Is this for a game?

It probably is. I think it so because of the mention of 'fullscreen', and the use of the pixelgetcolor function. But, for the benefit of a doubt, I'll offer this:

 

HotKeySet("4", "_statechange") ;disable
HotKeySet("5", "_statechange") ;enable
HotKeySet("{ESC}", "_terminate")

$variable = 1

While 1
    If $variable Then
        MsgBox(0, "", "enabled", 1)
    Else
        MsgBox(0, "", "disabled", 1)
    EndIf
    Sleep(500)
Wend

Func _statechange()
    Switch @HotKeyPressed
        Case "4" ;disable
            $variable = 0
        Case "5" ;enable
            $variable = 1
    EndSwitch
EndFunc

Func _terminate()
    Exit
EndFunc
edit: I just noticed that I got the enable and disable HotKey's reversed. Not really a problem though.. Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I need some help somdcomputerguy, The disable function is not really working out for me, due to the fact that I dont think I'm placing the code in correctly  

This is what I god atm

HotKeySet("5", "_statechange") ;disable
HotKeySet("4", "_statechange") ;enable


$variable = 1

 While 1
   If $variable Then     
    $color = PixelGetColor(@DesktopWidth / 2, @DesktopHeight / 2)
   If $color = 16711680 Or $color = 16646144 Then
        MouseClick ("middle")
        Sleep(10)
Endif 
  Else 
(Dont Really know what to do here. Sorry got a little Lost.)
  Wend 
  
  
Func _statechange()
    Switch @HotKeyPressed
        Case "5" ;disable
            $variable = 0
        Case "4" ;enable
            $variable = 1
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I corrected the code somewhat, I also deleted the Else part, as it's not really needed in this case I think. Try this out and see if it works for you. Remember, if only one thing is executed in an If loop, you can do that right after the Then, and you don't need an EndIf.

HotKeySet("5", "_statechange") ;disable
HotKeySet("4", "_statechange") ;enable

$variable = 1

While 1
 If $variable Then
  $color = PixelGetColor(@DesktopWidth / 2, @DesktopHeight / 2)
  If $color = 16711680 Or $color = 16646144 Then MouseClick ("middle")
 EndIf
 Sleep(10)
Wend

Func _statechange()
 Switch @HotKeyPressed
  Case "5" ;disable
   $variable = 0
  Case "4" ;enable
   $variable = 1
 EndSwitch
EndFunc
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Does it work when you just run the script without opening up your full screen app?

If so, then it is likely the your full screen app "eats" all keyboard actions.

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Does it work when you just run the script without opening up your full screen app?

If so, then it is likely the your full screen app "eats" all keyboard actions.

True. See, this works as expected:

HotKeySet("5", "_statechange") ;disable
HotKeySet("4", "_statechange") ;enable

$variable = 1

While 1
 If $variable Then
  ;$color = PixelGetColor(@DesktopWidth / 2, @DesktopHeight / 2)
  ;If $color = 16711680 Or $color = 16646144 Then MouseClick ("middle")
  MsgBox(0, "", "enabled", 1)
 EndIf
Sleep(10)
Wend

Func _statechange()
 Switch @HotKeyPressed
  Case "5" ;disable
   $variable = 0
  Case "4" ;enable
   $variable = 1
 EndSwitch
EndFunc
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Doubt there is a function in game that blocks keyboard functions due to the fact that I have used a similar script with "AC Tool". However AC tool is detected as a "Advantageous Program" hence blocked. 

Hence the alternation to AutoIt.

There must be a way. 

Share this post


Link to post
Share on other sites

This is for a game? You've just made several people very pissed I'm sure.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Lol yes it is BrewMan

Share this post


Link to post
Share on other sites

I highly figured it was for a game, but.. :bye:


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

FrequentUser,

Please read the Forum rules (there is also a link at bottom right of each page)before you post again. Take particular note of the bit about not discussing game automation - then you will understand why you will get no more help and this thread will now be locked. :naughty:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0