Jump to content
Sign in to follow this  
NoHAX

Hotkeys from Ini

Recommended Posts

NoHAX

Hi :)

I have small problem

I created small program (inspired by Kris7942) who can write ini file.

Ok program created this file but i cant read hotkeys from .ini :)

Here is my code

Opt("WinTitleMatchMode", 3)
Opt("SendAttachMode", 1)
Opt("SendKeyDelay", 35)
Opt("GUIOnEventMode", 1)
Opt("TrayAutoPause", 0)
Opt("GUIOnEventMode", 1); Change to OnEvent mode 

ConsoleWrite("Reading Includes" & @LF)

#include-once
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

ConsoleWrite("Includes readed" & @LF)
ConsoleWrite("Reading GUI 1" & @LF)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Ini Read", 423, 288, 434, 140)
$Group1 = GUICtrlCreateGroup("Settings", 8, 24, 649, 201)
$Input1 = GUICtrlCreateInput("", 96, 48, 313, 21)
$Label1 = GUICtrlCreateLabel("Text", 32, 48, 47, 17)
$Button5 = GUICtrlCreateButton("Set buttons", 8, 248, 131, 25, $WS_GROUP)
GUICtrlSetOnEvent($Button5, "_SetButtons")
GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

ConsoleWrite("Reading GUI 2" & @LF)
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Configure Control", 377, 210, 320, 253)
GUISetIcon("D:\004.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 1, 265, 193)
$InputWindow = GUICtrlCreateInput("Window", 16, 16, 145, 21)
$InputStart = GUICtrlCreateInput("Start", 16, 48, 145, 21)
$InputStop = GUICtrlCreateInput("Stop", 16, 80, 145, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ButtonOK = GUICtrlCreateButton("&OK", 286, 11, 75, 25, $WS_GROUP)
$ButtonCancel = GUICtrlCreateButton("&Cancel", 285, 44, 75, 25, $WS_GROUP)
$Buttonhelp = GUICtrlCreateButton("&Help", 285, 76, 75, 25, $WS_GROUP)
GUISetState(@SW_HIDE)
GUICtrlSetOnEvent($ButtonCancel, "_Cancel")
GUICtrlSetOnEvent($ButtonOK, "_OK")
#EndRegion ### END Koda GUI section ###
ConsoleWrite("All GUI Readed" & @LF)

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)

ConsoleWrite("Reading Ini settings" & @LF)
$INI = (@ScriptDir & "\Settings.ini")
$title = IniRead($INI, "Settings", "Window", "")
$Exit = IniRead($INI, "", "Exit", "")
$Start = IniRead($INI, "", "Start", "")
$hwnd = WinGetHandle($title)
ConsoleWrite("Ini settings readed" & @LF)

ConsoleWrite("Reading Hotkeys" & @LF)
HotKeySet("{"& $Exit &"}", "OnExit")
HotKeySet("{"& $Start &"}", "Start")
ConsoleWrite("Hotkey readed" & @LF)

ConsoleWrite("Checking Ini file" & @LF)
;============================== Check ini file ==============================
if FileExists(@ScriptDir & "\Settings.ini") Then
MsgBox(0, "Ini File", "Your configuration of ini file is complete" & @CRLF & "If you want change file, click on 'Set Buttons'")
GUISetState(@SW_HIDE, $Form2)
Else
MsgBox(0, "Ini File", "Your ini file doesnt exist" & @CRLF & "If you want set keys, just click on 'Set Buttons'")
GUISetState(@SW_SHOW, $Form2)   
EndIf
ConsoleWrite("Ini file checked" & @LF)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        EndSwitch
        WEnd

ConsoleWrite("Looking buttons" & @LF)
Func _SetButtons()
GUISetState(@SW_SHOW, $Form2)
    EndFunc
ConsoleWrite("Buttons found" & @LF)

ConsoleWrite("Reading functions" & @LF)
ConsoleWrite("Start()" & @LF)
Func Start()
While 1
Sleep(Random(200,600))
ControlSend($Title, "", "", "any msg" & Random(1, 20,1))
Sleep(Random(200,500))
ControlSend($Title, "", "", "{Enter}")
Sleep(Random(100,600))
ControlSend($Title, "", "", GUICtrlRead($input1))
Sleep(Random(GUICtrlRead($input4) *1000, GUICTRLREAD($input5) *1000))
ControlSend($Title, "", "", "{Enter}")
WEnd
EndFunc

ConsoleWrite("OnExit()" & @LF)
Func OnExit()
    Exit
EndFunc

ConsoleWrite("_Cancel()" & @LF)
Func _Cancel()
GUISetState(@SW_HIDE)
    EndFunc
    
ConsoleWrite("_OK()" & @LF)
    Func _OK()

        ConsoleWrite("Creating File" & @LF)
;============================== Creating File ==============================
if FileExists(@ScriptDir & "\Settings.ini") then
FileDelete(@ScriptDir & "\Settings.ini")
EndIf
$file = FileOpen("Settings.ini", 1)
; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file, "[Setings]" & @CRLF)
FileWriteLine($file, "Window = " & guictrlread($InputWindow) & @CRLF)
FileWriteLine($file, "Start = " & guictrlread($InputStart) & @CRLF)
FileWriteLine($file, "Exit = " & guictrlread($InputStop) & @CRLF)
FileClose($file)
GUISetState(@SW_HIDE)
EndFunc
ConsoleWrite("All Functions readed" & @LF)
ConsoleWrite("File created" & @LF)
ConsoleWrite("Rest of code..." & @LF)

;===============================================================================
;
; Function Name:  _SendMinimized()
;===============================================================================
Func _SendShiftMinimized($press)
;~  Local $VK_SHIFT = 0x0010
;~  Local $VK_G = 0x47
;~  Local $VK_OEM_4 = 0xDB
    Local $VK_OEM_6 = 0xDD
;~  Local $WM_KEYDOWN = 0x0100
;~  Local $WM_IME_KEYDOWN = 0x0290
    local $KEYEVENTF_KEYUP = 0x02
    if $press = 1 Then
        DllCall("user32.dll","int", "keybd_event", _
        "byte", $VK_OEM_6, _
        "byte", $VK_OEM_6, _
        "int", 0, _
        "int", 0 );
    Elseif $press = 0 Then
        DllCall("user32.dll","int", "keybd_event", _
        "byte", $VK_OEM_6, _
        "byte", $VK_OEM_6, _
        "int", $KEYEVENTF_KEYUP, _
        "int", 0 );
    EndIf
    ;DllCall("user32.dll", "int", "SendMessage", _
    ;"hwnd", WinGetHandle($Window), _
    ;"int", $WM_KEYDOWN, _
    ;"int", $VK_SHIFT, _
    ;"long", 0) 
EndFunc   ;==>_SendMinimized
 Func _MakeLong($LoWord,$HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

I think the problem exist in:

ConsoleWrite("Reading Ini settings" & @LF)
$INI = (@ScriptDir & "\Settings.ini")
$title = IniRead($INI, "Settings", "Window", "")
$Exit = IniRead($INI, "", "Exit", "")
$Start = IniRead($INI, "", "Start", "")
$hwnd = WinGetHandle($title)
ConsoleWrite("Ini settings readed" & @LF)

ConsoleWrite("Reading Hotkeys" & @LF)
HotKeySet("{"& $Exit &"}", "OnExit")
HotKeySet("{"& $Start &"}", "Start")
ConsoleWrite("Hotkey readed" & @LF)

But i am not sure

Can someone help me? pls :P

Share this post


Link to post
Share on other sites
TurionAltec

$Exit = IniRead($INI, "Setings", "Exit", "")
$Start = IniRead($INI, "Setings", "Start", "")

"Section" isn't an optional parameter of Iniread.

And technically it should be spelled "Settings"

Share this post


Link to post
Share on other sites
NoHAX

$Exit = IniRead($INI, "Setings", "Exit", "")
$Start = IniRead($INI, "Setings", "Start", "")

"Section" isn't an optional parameter of Iniread.

And technically it should be spelled "Settings"

But doesnt work :)

I totally dont understand why.

If i replace

HotKeySet("{F1}", "OnExit")
HotKeySet("{F2}", "Start")

with

HotKeySet("{"& $Exit &"}", "OnExit")
HotKeySet("{"& $Start &"}", "Start")

The program will be work :\

Share this post


Link to post
Share on other sites
Authenticity

A typical ini file should be in the form:

[Section1]
keyname1=value
keyname2=value
.
.
.

[Section2]
keyname1=value
keyname2=value
.
.
.

Also make sure you don't have any typos, i.e typing "Setings" but the section name is "Settings". Copy and paste is one reliable approach.

By the way, if the ini keyname is not found you're going to use "" as the hotkey. Maybe it'll be better to use something like:

$Exit = IniRead($INI, "Settings", "Exit", "^1") ; Ctrl+1 for example.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.