Jump to content

HotKeySet


Smurfin
 Share

Recommended Posts

Hi,

I'd like to ask how do I make HotKeySet to work with same script which is run multiple times ?

I have made an app to run some script for an online game, and I use multi clients on this game, so when I press this key to toggle on/off the script, I expect the key to work to each of the running script simultaneously, but I was wrong, is it possible to make it work ?

I've read the AutoIT help file about Hotkeyset, and it mentioned this :

Remarks

If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously. (The second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.)

A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted. Exceptions are as follows:

1) If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the blocking function completes. MsgBox and FileSelectFolder are examples of blocking functions. Try the behavior of Shift-Alt-d in the Example.

2) If you have paused the script by clicking on the AutoIt Tray icon, any hotkeys pressed during this paused state are ignored.

I send along the source code if anyone willing to try, only to run the script you must have any window open with name "Smurfin", easiest is just extract these files to a folder named "Smurfin" and keep it open then compile the script to exe, run it twice or more and try the hotkeyset function, shortcut for the hotkeys set in it are {F10} and {F11}, try to press any of them and only one instance of this script will work with the toggle.

any help would be very appreciated.

Smurfin.rar

Link to comment
Share on other sites

Hi,

I'd like to ask how do I make HotKeySet to work with same script which is run multiple times ?

I have made an app to run some script for an online game, and I use multi clients on this game, so when I press this key to toggle on/off the script, I expect the key to work to each of the running script simultaneously, but I was wrong, is it possible to make it work ?

I've read the AutoIT help file about Hotkeyset, and it mentioned this :

Remarks

If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously. (The second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.)

A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted. Exceptions are as follows:

1) If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the blocking function completes. MsgBox and FileSelectFolder are examples of blocking functions. Try the behavior of Shift-Alt-d in the Example.

2) If you have paused the script by clicking on the AutoIt Tray icon, any hotkeys pressed during this paused state are ignored.

I send along the source code if anyone willing to try, only to run the script you must have any window open with name "Smurfin", easiest is just extract these files to a folder named "Smurfin" and keep it open then compile the script to exe, run it twice or more and try the hotkeyset function, shortcut for the hotkeys set in it are {F10} and {F11}, try to press any of them and only one instance of this script will work with the toggle.

any help would be very appreciated.

Hi there,

Define a range of hotkeys to use regarding the possible number of script instances.

Try to capture if the script is already running and use the next number for the hotkey.

if running then hotkey equal to previous plus one.

i hope i make my self clear :)

cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

Do you mean using other key for hotkey ?

coz I like it with F10/F11 since the game already used lots other keys.

and it's kinda defeat the purpose if using other keys for each

Yes that was the ideia... but its useless...

Are the script active, i mean, you need to get thw window game focus?

just a thought :)

You could disable hotkey whenever ths cript lose focus :)

Cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

Yes that was the ideia... but its useless...

Are the script active, i mean, you need to get thw window game focus?

just a thought :)

You could disable hotkey whenever ths cript lose focus :)

Cheers

No, it runs in the background, it works like this : if F10 is pressed once, it'll run a function to check if a checkbox status is ON or OFF, if the checkbox is ON, then it set the gui_checked and vice versa, and if that status is ON then it'll write a value to a memory address (act like freeze a value in cheat engine or other similar app), this is looped until the checkbox status is changed again using F10 or by directly check/uncheck the checkbox to the interface using mouseclick

here is the screenshot and the source, and also settings in .ini file. Sorry if its too long and takes so much page space. ^^

Posted Image

===========
SmurfIT.ini
===========
[Settings]
Window Name=Element Client              -> Window Name which this app will work on
Base Address=9607148                      -> Base Address, by default is PW Indo
Fly Offset=1592                        -> Offsets for Flyhack, by default is PW Indo
Jump Offset=2836                          -> Offsets for Jumphack, by default is PW Indo    
Fly Hotkey={F10}                          -> Hotkey for on/off toggle FlyHack
Jump Hotkey={F11}                        -> Hotkey for on/off toggle JumpHack  
Hotkey1=!{F1}                            -> '!' means {ALT} key, that's how AutoIT represent it, '^' is for {Ctrl}
key1=6                                  -> the key to be sent to a window name of your choice (this can be changed realtime from the interface)  
Delay1=50                                -> delay between each key press, 1000 is 1 second (this can be changed realtime from the interface)
sendkey_to_this_window=Element Client    -> If you use dual/multi client, you might want to send the keypress to another client 
                                             (this can be changed realtime from the interface as well)
Smurfin_Object=ON                        -> this one is just for fun, turn it ON to create a Smurfin/Smurfette Object, while it's 'ON' the GUI will have a slider
                                             where you can set the transparency of the object. Turn this OFF to completely run the program in normal form and
                                             remove the Smurfin object (it's annoying with this option ON ^^) ). This is ON by default

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

#include <NomadMemory.au3>
#include <Memory.au3>
#include <GUIConstants.au3>
#include <Array.au3>



;Opt("MustDeclareVars", 1)
;Check Ini File
Opt("WinTitleMatchMode", 3)
If FileExists("SmurfIT.ini") Then
Else
    IniWrite("SmurfIT.ini", "Settings", "Window Name", "Element Client")
    IniWrite("SmurfIT.ini", "Settings", "Base Address", "9607148")
    IniWrite("SmurfIT.ini", "Settings", "Fly Offset", "1592")
    IniWrite("SmurfIT.ini", "Settings", "Jump Offset", "2836")
    IniWrite("SmurfIT.ini", "Settings", "Fly Hotkey", "{F10}")
    IniWrite("SmurfIT.ini", "Settings", "Jump Hotkey", "{F11}")
    IniWrite("SmurfIT.ini", "Settings", "Hotkey1", "!{F1}")
    IniWrite("SmurfIT.ini", "Settings", "key1", "6")
    IniWrite("SmurfIT.ini", "Settings", "Delay1", "50")
    IniWrite("SmurfIT.ini", "Settings", "sendkey_to_this_window", "Element Client")
    IniWrite("SmurfIT.ini", "Settings", "Smurfin_Object", "ON")

EndIf

;checking client name with window name in ini file, if not match then ask for new wtitle to work on, if input error then Exit
$ini_wtitle=string(iniread("SmurfIT.ini","Settings","Window Name",""))
$CheckWinExists=WINEXISTS($ini_wtitle)

if $CheckWinExists=0 then $ini_wtitle = InputBox("window name not found" , "Please enter your now running PW Client win title" & @CRLF & "or choose cancel to exit", "", "", 270, 140)
    If @error Then
        Exit(1)
    EndIf
$CheckWinExists=WINEXISTS($ini_wtitle)
if $CheckWinExists=0 then 
    MsgBox(4096,"error", "Cannot find window name :" & " " &$ini_wtitle)
    Exit
else
EndIf
$CheckWinExists=WINEXISTS($ini_wtitle)
if $CheckWinExists=0 then exit
;end of checking client name

Func CheckWinExistsInfoWindow()
guicreate("tes",200,200)
guictrlcreatelabel($ini_wtitle,1,1,200,20)
guictrlcreatelabel($CheckWinExists,1,21,200,20)
guisetstate()
$msg=0
While $msg <> $GUI_EVENT_CLOSE
      $msg = GuiGetMsg()
    
WEnd
Exit
EndFunc


$APP_BASE_ADDRESS=iniread("SmurfIT.ini","Settings","Base Address","")
Global $OFFSET_HP[3]
Global $OFFSET_JUMP[3]
Global $OFFSET_FLY[3]
$OFFSET_JUMP[1]=32
$OFFSET_JUMP[2]=iniread("SmurfIT.ini","Settings","Jump Offset","")
$OFFSET_FLY[1]=32
$OFFSET_FLY[2]=iniread("SmurfIT.ini","Settings","Fly Offset","")
Global $PROCESS_ID = WinGetProcess($ini_wtitle)
Global $PROCESS_INFORMATION = _MemoryOpen($PROCESS_ID)
Global $FLY_CBOX_STATUS="OFF"
Global $JUMP_CBOX_STATUS="OFF"

;GUI
$APPLICATION_TITLE= "Smurf IT!" & " - " & iniread("SmurfIT.ini","Settings","Window Name","")
$smurfin_obj_status=iniread("SmurfIT.ini","Settings","Smurfin_Object","")
If $Smurfin_Obj_status="ON" then 
Guicreate($APPLICATION_TITLE, 270,150)
$iSlider = GUICtrlCreateSlider(50, 121, 210, 20)
GUICtrlSetLimit($iSlider, 255, 0)
GUICtrlSetData ($iSlider, 255)
Guictrlcreatelabel("Slide to 0"& @CRLF & "to hide Smurfin",1,110,60,40)
Else
 Guicreate($APPLICATION_TITLE, 270,120)
EndIf
GuiSetIcon("Smurfette-icon.bmp", 0)
Global $FLY_CBOX=GuiCtrlCreateCheckbox("Fly Hack", 5, 5, 80, 20)
Global $JUMP_CBOX=GuiCtrlCreateCheckbox("Jump Hack", 5, 25, 80, 20)
Global $InfoON=guictrlcreatebutton("On",35,49,20,17)
Global $InfoOFF=guictrlcreatebutton("Off",55,49,20,17)
guictrlcreatelabel("Renamer :",90,5,80,20)
$oldname=GUICtrlCreateinput("Element Client",95,25,85,20)
$newname=GUICtrlCreateinput("Element Client2",95,50,85,20)
Global $RenameIT=GUICtrlCreateButton("RenameIT!",95,75,85,20)

$ini_Hotkey_Key1=string(iniread("SmurfIT.ini","Settings","HotKey1",""))
$iniKeypress1 = IniRead("SmurfIT.ini","Settings","Key1","")
$iniDelay1 = IniRead("SmurfIT.ini","Settings","Delay1","")
$autokey_status="OFF"

Global $Key1_CBOX=GuiCtrlCreateCheckbox($ini_Hotkey_Key1, 195, 3, 80, 20)

GUICtrlCreateLabel("Key:",195,23,20,18)
$inputkeypress=GUICtrlCreateinput($iniKeypress1,215,21,30,15)
$sav1=GUIctrlcreatebutton("sav",245,21,23,15)
$inputdelay=GUICtrlCreateLabel("Dly:",195,39,20,15)
GUICtrlCreateinput($iniDelay1,215,38,30,15)
$sav2=GUIctrlcreatebutton("sav",245,38,23,15)
GUICtrlCreateLabel("SendToWin:",187,60,58,15)
$iniSendKeypressToThisWindow = IniRead("SmurfIT.ini","Settings","sendkey_to_this_window","")
$inputnewwinname=GUICtrlCreateinput($iniSendKeypressToThisWindow,187,74,82,20)
$sav3=GUIctrlcreatebutton("sav",245,58,23,15)

guictrlcreatelabel("by smurfin.mail@gmail.com",70,105,200,20)
guictrlcreatelabel("outline",1,1,269,105,0x12)
guictrlcreatelabel("infobox",5,47,73,22,0x12)
guictrlcreatelabel("line1",85,5,1,101,0x11)
guictrlcreatelabel("line2",185,5,1,101,0x11)
guictrlcreatelabel("Info",10,50,25,17)

$msg=0
$Info="OFF"
GuiSetState()

$LABEL_JUMP_STATUS = GUICtrlCreateLabel("", 15, 69, 40, 18)
$LABEL_FLY_STATUS = GUICtrlCreateLabel("", 15, 84, 50, 18)


$iniFlyHotkey=string(iniread("SmurfIT.ini","Settings","Fly Hotkey",""))
$iniJumpHotkey=string(iniread("SmurfIT.ini","Settings","Jump Hotkey",""))

Hotkeyset($iniFlyHotkey,"ToggleFly")
Hotkeyset($iniJumpHotkey,"ToggleJump")
Hotkeyset($ini_Hotkey_Key1,"Toggle_Autokey")


if $smurfin_obj_status="ON" then smurfinobj()
While 1
    
    If $FLY_CBOX_STATUS="ON" Then StartFly()
    If $FLY_CBOX_STATUS="OFF" Then StopFly()
    If $JUMP_CBOX_STATUS="ON" Then StartJump()
    If $Info="ON" Then Info_ON()
    If $Info="OFF" Then Info_OFF()
    If $autokey_status="ON" then Autokey1()

    $msg = GuiGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        if $smurfin_obj_status="ON" then
        ; Release resources
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_Shutdown()
            Else
        send("{!}1")
        send("{^}1")
        Endif
        Exit
        
         Case $FLY_CBOX
             ToggleFly()
    
         Case $JUMP_CBOX
             ToggleJump()
             
         Case $InfoON
             $Info="ON"
         
         Case $InfoOFF
             $Info="OFF"
        
         Case $RenameIT
             winsettitle(guictrlread($oldname),"",guictrlread($newname))
         
         Case $Key1_CBOX
             toggle_autokey()
         
         Case $sav1
             
             iniwrite("SmurfIT.ini","Settings","key1",guictrlread($inputkeypress))
             $iniKeypress1 = IniRead("SmurfIT.ini","Settings","Key1","")
         
         Case $sav2
             iniwrite("SmurfIT.ini","Settings","delay1",guictrlread($inputdelay))
             $iniDelay1 = IniRead("SmurfIT.ini","Settings","Key1","")
         
         Case $sav3
             iniwrite("SmurfIT.ini","Settings","sendkey_to_this_window",guictrlread($inputnewwinname))
             $iniSendKeypressToThisWindow = IniRead("SmurfIT.ini","Settings","sendkey_to_this_window","")
    
      EndSwitch
  WEnd
  
Func ToggleFly()
    If $FLY_CBOX_STATUS="ON" Then
        Guictrlsetstate($FLY_CBOX,$GUI_UNCHECKED)
        $FLY_CBOX_STATUS="OFF"
    Else
        Guictrlsetstate($FLY_CBOX,$GUI_CHECKED)
        $FLY_CBOX_STATUS="ON"
    EndIf
    
EndFunc

Func ToggleJump()
    If $JUMP_CBOX_STATUS="ON" Then
        Guictrlsetstate($JUMP_CBOX,$GUI_UNCHECKED)
        $JUMP_CBOX_STATUS="OFF"
    Else
        Guictrlsetstate($JUMP_CBOX,$GUI_CHECKED)
        $JUMP_CBOX_STATUS="ON"
    EndIf
EndFunc

Func StartFly()
    _MemoryPointerWrite($APP_BASE_ADDRESS, $PROCESS_INFORMATION, $OFFSET_FLY,43025)
EndFunc

Func StopFly()
    _MemoryPointerWrite($APP_BASE_ADDRESS, $PROCESS_INFORMATION, $OFFSET_FLY,43008)
EndFunc

Func StartJump()
    _MemoryPointerWrite($APP_BASE_ADDRESS, $PROCESS_INFORMATION, $OFFSET_JUMP,1)
EndFunc

Func Toggle_Autokey()
    If $autokey_status="ON" Then
        Guictrlsetstate($Key1_CBOX,$GUI_UNCHECKED)
        $autokey_status="OFF"
       ;GUICtrlSetData($label3, $Checked3)
    Else
        Guictrlsetstate($Key1_CBOX,$GUI_CHECKED)
        $autokey_status="ON"
       ;GUICtrlSetData($label3, $Checked3)
    EndIf
EndFunc


Func Info_ON()
        
        $JUMP = _MemoryPointerRead($APP_BASE_ADDRESS, $PROCESS_INFORMATION, $OFFSET_JUMP)
        $FLY = _MemoryPointerRead($APP_BASE_ADDRESS, $PROCESS_INFORMATION, $OFFSET_FLY) 
        GUICtrlSetData($LABEL_JUMP_STATUS, "Jump: " & $JUMP[1])
        GUICtrlSetData($LABEL_FLY_STATUS, "Fly: " & $FLY[1])        
EndFunc

Func Info_OFF()
        GUICtrlSetData($LABEL_JUMP_STATUS, "")
        GUICtrlSetData($LABEL_FLY_STATUS, "")
EndFunc

FUNC autokey1()
    
    ControlSend($iniSendKeypressToThisWindow,"","",$iniKeypress1)  
    sleep($iniDelay1)
    
EndFunc

Func SmurfinObj()
Global Const $AC_SRC_ALPHA    = 1

; ====================================================================================================

===========================
; Global variables
; ====================================================================================================

===========================
Global $hGUI1, $hGUI2, $iLabel1, $iLabel2, $iSlider, $hImage,$tes

;$hGui1=Guicreate("TES", 400,400)

global $msg = 0
GUISetState()

;GuiCtrlCreateLabel("Sample Tab with tabItems", 250, 40)
GuiCtrlCreateTabItem("Two")
guictrlcreatepic("smurfinTR.png",1,1,156,255)
GuiCtrlCreateTabItem("")

GuiCtrlCreateTabItem("Three")

;===================================================
; 01. Create layered child window
$hGUI2 = GUICreate("Smurfin", 250, 250, -1, -1, -1, $WS_EX_LAYERED, $hGUI1)

; 02. Load layered image
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("SmurfinTR.png")

;03. ~ $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\Torus.png")
SetBitMap($hGUI2, $hImage, 255)
GUISetState()

; 04. Register notification messages
GUIRegisterMsg($WM_HSCROLL  , "WM_HSCROLL"  )
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

;===================================================
 EndFunc


; ====================================================================================================

===========================
; Handle the WM_HSCROLL notificaton so that we can change the opacity in real time
; ====================================================================================================

===========================
Func WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)
  SetBitMap($hGUI2, $hImage, GUICtrlRead($iSlider))
EndFunc

; ====================================================================================================

===========================
; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ====================================================================================================

===========================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if ($hWnd = $hGUI2) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc

; ====================================================================================================

===========================
; SetBitMap
; ====================================================================================================

===========================
Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC  ($hMemDC)
EndFunc
Edited by Smurfin
Link to comment
Share on other sites

Instead of using HotKetSet use _IsPressed and then any number of scripts can detect the same key.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

by using _IsPressed, can I activate scripts even if I stay active in other window, like in game window, so while still playing I can execute scripts remotely using that _IsPressed?

I don't know if the game will affect it. As long as your script can detect the key then I suppose you can then do what you want, but if you have more than one script trying to react to the same key you need to make sure that what one script does won't conflict with what another does. The easiest way to find out is to just try it.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

oh alright ^^

thanks anyone, I've just used another method for it.

Can you tell us what method?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...