Jump to content

Multiple For Loops work at same time.


Go to solution Solved by Gianni,

Recommended Posts

here is my current code  im trying to have full words be the hotkey each will work individually but i cannot get the for loops to work properly to have multiples work at a time

 

HotKeySet("{ESC}","gone");allow us to quit
 
Global $code = "facebook";the code to detect
Global $arrayc = StringSplit($code, "")
Global $progress = 0;how many keys in sequence detected
 
Global $code2 = "gmail";the code to detect
Global $arrayc2 = StringSplit($code2, "")
Global $progress2 = 0;how many keys in sequence detected
 
 
 
 
For $n = 1 To $arrayc[0]
    HotKeySet($arrayc[$n], "hcoder")
 
 Next
 
For $n2 = 1 To $arrayc2[0]
    HotKeySet($arrayc2[$n2], "hcoder2")
 
 Next
 
;add some keys that are not in the code but chosen so it is unlikely 
;that the keys will occur in sequence without one of these being pressed
HotKeySet("{SPACE}","hcoder")
HotKeySet("{ENTER}","hcoder")
;add more if needed.
 
While 1;hang around while waiting for keys
    Sleep(20)
    
WEnd
 
Func hcoder()
    HotKeySet(@HotKeyPressed)
    Send(@HotKeyPressed)
    If @HotKeyPressed = $arrayc[$progress + 1] Then
        $progress += 1
        ConsoleWrite("count = " & $progress & @LF)
    Else
        $progress = 0
    EndIf
    If $progress >= StringLen($code) Then
        Run("C:Program Files (x86)GoogleChromeApplication" & "chrome.exe facebook.com")
$progress = 0
EndIf
    HotKeySet(@HotKeyPressed, "hcoder")
 EndFunc ;==>hcoder
 
 Func hcoder2()
    HotKeySet(@HotKeyPressed)
    Send(@HotKeyPressed)
    If @HotKeyPressed = $arrayc2[$progress2 + 1] Then
        $progress2 += 1
        ConsoleWrite("count = " & $progress2 & @LF)
    Else
        $progress2 = 0
    EndIf
    If $progress2 >= StringLen($code2) Then
        Run("C:Program Files (x86)GoogleChromeApplication" & "chrome.exe gmail.com")
$progress2 = 0
EndIf
    HotKeySet(@HotKeyPressed, "hcoder2")
 EndFunc ;==>hcoder2
 
Func gone()
    
    Exit

 EndFunc ;==>gone 

Link to comment
Share on other sites

Look into GUISetAccelerators it might be what you want.

No nevermind, wasn't thinking.

I tried using _IsPressed to set up some key chords but no real luck so far.  Currently I have to hold the keys at the exact same time it seems.

Edited by jaberwocky6669
Link to comment
Share on other sites

Ok, this works if you type gmail.  Or if you're lucky enough to hold them down at the exact same time.  This is just proof of concept and not proper code.

#include <Misc.au3>

Global $chord_g = False
Global $chord_m = False
Global $chord_a = False
Global $chord_i = False
Global $chord_l = False

Do
  If _IsPressed("47") Then $chord_g = True
  If _IsPressed("4D") Then $chord_m = True
  If _IsPressed("41") Then $chord_a = True
  If _IsPressed("49") Then $chord_i = True
  If _IsPressed("4C") Then $chord_l = True
  
  If $chord_g And $chord_m And $chord_a And $chord_i And $chord_l Then 
    MsgBox(0, '', "GMAIL")
    
    $chord_g = False
    $chord_m = False
    $chord_a = False
    $chord_i = False
    $chord_l = False
  EndIf
  
  If _IsPressed("1B") Then Exit
  
  Sleep(100)
Until False
Edited by jaberwocky6669
Link to comment
Share on other sites

Ok, try this!  This requires the latest beta 3.3.11.2

If you type in g m a i l then you'll see the message box, otherwise if you type gmaiol then nothing.  Neat-o!

Edit: still has an issue, or two, or three...

Edit: Ironed out one issue.  Next issue, handling more than one chord.

See the next post.

<snip>
Edited by jaberwacky
Link to comment
Share on other sites

Look, got it to work for facebook too. Kewl!

#include <WinAPI.au3>

#include <WindowsConstants.au3>

HotKeySet("{ESC}", _exit)

Global Const $ll_kb_hook = _register_low_level_keyboard_hook()

Do
  Sleep(100)
Until False

Volatile Func _ll_keyboard_proc($code, $w_param, $l_param)
  Local Static $gmail_chord[][] = [["71" , "77" , "65" , "73" , "76"], _
                                   [0    , 0    , 0    , 0    , 0]]

  Local Static $gmail_index = 0

  Local Static $facebook_chord[][] = [["70" , "65" , "67" , "69" , "66" , "79" , "79" , "75"], _
                                      [0    , 0    , 0    , 0    , 0    , 0    , 0    , 0]]

  Local Static $facebook_index = 0

  Local Const $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $l_param)

  Switch $code >= 0
    Case True

      Switch $w_param
        Case $WM_KEYDOWN

          Switch $tKEYHOOKS.vkCode
            Case $gmail_chord[0][$gmail_index]

              Switch $gmail_chord[1][$gmail_index]
                Case 0
                  $gmail_chord[1][$gmail_index] = 1

                  If $gmail_index < 4 then
                    $gmail_index += 1
                  Else
                    MsgBox($MB_TOPMOST, '', "GMAIL")

                    _gmail_chord_refresh($gmail_chord, $gmail_index)
                  EndIf
              EndSwitch

            Case $facebook_chord[0][$facebook_index]

              Switch $facebook_chord[1][$facebook_index]
                Case 0
                  $facebook_chord[1][$facebook_index] = 1

                  If $facebook_index < 7 then
                    $facebook_index += 1
                  Else
                    MsgBox($MB_TOPMOST, '', "FACEBOOK")

                    _facebook_chord_refresh($facebook_chord, $facebook_index)
                  EndIf
              EndSwitch

            Case Else
              _gmail_chord_refresh($gmail_chord, $gmail_index)
              
              _facebook_chord_refresh($facebook_chord, $facebook_index)
          EndSwitch
      EndSwitch
  EndSwitch

  Return _WinAPI_CallNextHookEx($ll_kb_hook, $code, $w_param, $l_param)
EndFunc

Func _gmail_chord_refresh(Byref $gmail_chord, Byref $gmail_index)
  $gmail_chord[1][0] = 0
  $gmail_chord[1][1] = 0
  $gmail_chord[1][2] = 0
  $gmail_chord[1][3] = 0
  $gmail_chord[1][4] = 0
 
  $gmail_index = 0
EndFunc

Func _facebook_chord_refresh(Byref $facebook_chord, Byref $facebook_index)
  $facebook_chord[1][0] = 0
  $facebook_chord[1][1] = 0
  $facebook_chord[1][2] = 0
  $facebook_chord[1][3] = 0
  $facebook_chord[1][4] = 0
  $facebook_chord[1][5] = 0
  $facebook_chord[1][6] = 0
  $facebook_chord[1][7] = 0
 
  $facebook_index = 0
EndFunc

Func _register_low_level_keyboard_hook()
  Local Const $keybooard_proc_callback = DllCallbackRegister(_ll_keyboard_proc, "long", "int;wparam;lparam")

  Return _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($keybooard_proc_callback), _WinAPI_GetModuleHandle(0))
EndFunc

Func _exit()
  Exit
EndFunc
Edited by jaberwacky
Link to comment
Share on other sites

If I understand your requirements correctly Mandar's hotStrings function will do what you want.


 

It works similar to Hotkeys except that the trigger is a whole word not just a single key or key combination.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

  • Solution

Hi MIchaelfjsmith2
this should do
multiple "LongHotKeys" allowed

; here dim the array and enter the "longHotKeys"
Global $Token[4] = ["facebook", "gmail", "pincopanco", "hello"]
Global $Index[UBound($Token)]
Global $Match[UBound($Token)]
; ---- Initialize hotkeys ------------
For $x = 0 To UBound($Token) - 1
    $Index[$x] = 1
    $Match[$x] = 0
    For $i = 1 To StringLen($Token[$x])
        HotKeySet(StringMid($Token[$x], $i, 1), "LongHotKey")
    Next
Next

HotKeySet("{ESC}", "gone") ; allow us to quit

While 1
    Sleep(100)
WEnd

Func LongHotKey()
    $HotKeyPressed = @HotKeyPressed
    HotKeySet($HotKeyPressed) ; Disable hotkey to prevent looping
    Send($HotKeyPressed) ; send key to destination
    HotKeySet($HotKeyPressed, "LongHotKey") ; enable hotkey again

    For $x = 0 To UBound($Token) - 1
        $KeyExpected = StringMid($Token[$x], $Index[$x], 1)
        If $HotKeyPressed = $KeyExpected Then
            $Index[$x] += 1
            $Match[$x] += 1
            If $Match[$x] = StringLen($Token[$x]) Then
                ; ConsoleWrite("Detected -> " & $Token[$x] & @CRLF)
                Run_It($x) ; fire what you want
                $Index[$x] = 1
                $Match[$x] = 0
            EndIf
        Else
            $Index[$x] = 1
            $Match[$x] = 0
        EndIf
    Next
EndFunc   ;==>LongHotKey

Func Run_It($x) ; $x contains the index of the fired LongHotKey

    ConsoleWrite("Detected -> " & $Token[$x] & @CRLF)

    Switch $x
        Case 0
            ;   Run("C:\Program Files (x86)\Google\Chrome\Application" & "\chrome.exe facebook.com")
        Case 1
            ;   Run("C:\Program Files (x86)\Google\Chrome\Application" & "\chrome.exe gmail.com")
        Case 2
            ;   option 3
        Case 3
            ;   option 4
    EndSwitch
EndFunc   ;==>Run_It

Func gone()
    Exit
EndFunc   ;==>gone

Edit:

changed listing from

case 1 .... case 4

to

case 0 .... case 3

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

google translate does not translate this, but I can imagine ....

you are welcome

 

He insulted your donkey. I wouldn't stand for it. Men have been murdered for less atrocious acts.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

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...