Jump to content
Sign in to follow this  

Passing a "Flag" between scripts; Alternatives to HotKeySet()

Recommended Posts


I'm hoping you can help me.


Use an alternative to HotKeySet() to pass flags between scripts. HotKeySet() limits full functionality of the Keyboard which is undesirable.


What I have been doing

I've been using HotKeySet() to successfully pass flags between scripts. In the script below hotkeys, h, k, suspend the loop. 

#include <Misc.au3>

Local $hDLL = DllOpen ("user32.dll")

;Declare Variables
Global $Paused = 0
Local $i = 0
Local $k = 0
Local $j = 0
Local $v = 0

;Define HotKeys
HotKeySet("{h}", "FSuspend")
HotKeySet("{k}", "ASuspend")
HotKeySet("{m}", "TogglePause")

While 1                                             ;Always running, 10 ms loops
      While $j = 0 and $v = 0                           ;Run loop if not suspended
         $h = RedCheck(1403, 1331)                          ;Get RGB values of pixelb
         $x = Number($h[3])
         $q = Number($h[2])
         $e = Number($h[1])
         If ($x >= $q) Then                                 ;See if more red than green
            $i = 1
         If ($x >= $e) Then                                 ;See if more red than blue
            $k = 1
         If $i + $k < 2 Then                                ;If less red than blue or green, wait a bit and send number 4
            $i = 1                                              ;Set interim varibles to 1 because pixel has now changed to red dominant because of sending number 4
            $k = 1
            Send ("{4}")
            While ($i + $k = 2) And $v = 0                      ;While pixel has more red than either blue or green, and FSuspend isnt active, run 40 ms loops, delaying further action
               $h = RedCheck(1042, 1308)                            ;Get RGB value of pixel every 40ms
               $x = Number($h[3])
               $q = Number($h[2])
               $e = Number($h[1])
               If ($q >= $x) Then                                   ;See if more green than red
                  $i = 0
               If ($e >= $x) Then                                   ;See if more blue than red
                  $k = 0
               Sleep (40)
         Sleep (20)
         $i = 0                                         ;Reset interim variables
         $k = 0
   Sleep (10)

;Function to find numerical values of R,G,B
Func RedCheck($x, $y)
   $hex = Hex(PixelGetColor($x, $y), 6)
   $r = Dec(StringRight($hex, 2)) & "|"
   $g = Dec(StringMid($hex, 3,2)) & "|"
   $b = Dec(StringLeft($hex, 2))
   Return StringSplit($r & $g & $b, "|")

;Suspend loop method 1
Func FSuspend()
If $v = 0 Then
   $v = 1
   $v = 0

;Suspend loop method 2
Func ASuspend()
If $j = 0 Then
   $j = 1
   $j = 0

;Pause Script
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused

I use another separate script to: 

  1. Look for an event
  2. If event starts send("{h}") 
  3. Check if the event is ongoing
  4. If event ends send("{h}")

As a result, the script posted is effectively suspended for the duration of the event.


What I have tried

I've tried using HotKeySet() with F13-F24 as to not use any mapped keys but HotKeySet() doesn't seem to work with these virtual keys. I can successfully send virtual keys, but not have them register with HotKeySet(). All of the below hasn't worked:

HotKeySet("{F13}", "GenericFunction")
HotKeySet("{ASC 0x7C}", "GenericFunction")
HotKeySet("{ASC 124}", "GenericFunction")
HotKeySet(Asc(124), "GenericFunction")


Does anyone have any alternatives? 


Thank you in advance.

Share this post

Link to post
Share on other sites

There are several option to communicate between scripts. Just search for Mailslot  or Named pipes or $WM_COPYDATA which all could be used to exchange information between scripts.


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Share this post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...