Jump to content

How to make dynamic changes input?


 Share

Recommended Posts

I want to know how can I make the inputs change instantly when I type? at the moment it only changes after I click on another input.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 364, 153, 192, 124)

$label1 = GUICtrlCreateLabel("Chance", 80, 32, 59, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$label2 = GUICtrlCreateLabel("Payout", 228, 31, 53, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("49.50", 144, 104, 97, 41)
$Chance = GUICtrlCreateInput("49.50", 56, 63, 121, 21)
$Payout = GUICtrlCreateInput("2", 208, 63, 121, 21)

GUISetState(@SW_SHOW)

Global $WhichFunc = 0
Global $aFuncs[2]
$aFuncs[0] = _Func_1
$aFuncs[1] = _Func_2
Global $RW = 1


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Chance
            Chance()
        Case $Payout
            Payout()
        Case $Button1
                 $aFuncs[$WhichFunc] ()
            $WhichFunc = Not $WhichFunc
    EndSwitch
WEnd


Func Chance()
    $Read1 = GUICtrlRead($Chance)
    $data = 99 / $Read1
    GUICtrlSetData($Payout, $data)
    $data = 99 / $data
    If $RW = 1 Then
    GUICtrlSetData($Button1, $data)
    Else
    _Func_1()
    EndIf
    EndFunc
    Func Payout()
    $Read2 = GUICtrlRead($Payout)
    $data1 = 99 / $Read2
    $data1 = Round($data1, 5)
    GUICtrlSetData($Chance, $data1)
    If $RW = 1 Then
        GUICtrlSetData($Button1, $data1)
    Else
        _Func_1()
    EndIf
EndFunc

 Func _Func_2()
$Read1 = GUICtrlRead($Chance)
GUICtrlSetData($Button1, $Read1)
$RW = 1
 EndFunc

 Func _Func_1()
$Read2 = GUICtrlRead($Chance)
$Read2 = 99.99 - $Read2
GUICtrlSetData($Button1, $Read2)
$RW = 2
 EndFunc
Edited by Ventura
Link to comment
Share on other sites

Well I have solved it myself after searching for... I got a code for WinAPI that makes it what I want.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>


$Form1 = GUICreate("Form1", 364, 153, 192, 124)
$label1 = GUICtrlCreateLabel("Chance", 80, 32, 59, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$label2 = GUICtrlCreateLabel("Payout", 228, 31, 53, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("49.50", 144, 104, 97, 41)
$Chance = GUICtrlCreateInput("49.50", 56, 63, 121, 21)
$Payout = GUICtrlCreateInput("2", 208, 63, 121, 21)

GUISetState(@SW_SHOW)

Global $WhichFunc = 0
Global $aFuncs[2]
$aFuncs[0] = _Func_1
$aFuncs[1] = _Func_2
Global $RW = 1


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")




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

        Case $Payout

        Case $Button1
                 $aFuncs[$WhichFunc] ()
            $WhichFunc = Not $WhichFunc
    EndSwitch
WEnd

Func WM_COMMAND($hWinHandle, $iMsg, $wParam, $lParam)
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $Chance Then
        Chance()
    EndIf
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $Payout Then
        Payout()
    EndIf
EndFunc   ;==>WM_COMMAND


Func Chance()
    $Read1 = GUICtrlRead($Chance)
    $data = 99 / $Read1
    GUICtrlSetData($Payout, $data)
    $data = 99 / $data
    If $RW = 1 Then
    GUICtrlSetData($Button1, $data)
    Else
    _Func_1()
    EndIf
    EndFunc
    Func Payout()
    $Read2 = GUICtrlRead($Payout)
    $data1 = 99 / $Read2
    $data1 = Round($data1, 5)
    GUICtrlSetData($Chance, $data1)
    If $RW = 1 Then
        GUICtrlSetData($Button1, $data1)
    Else
        _Func_1()
    EndIf
EndFunc

 Func _Func_2()
$Read1 = GUICtrlRead($Chance)
GUICtrlSetData($Button1, $Read1)
$RW = 1
 EndFunc

 Func _Func_1()
$Read2 = GUICtrlRead($Chance)
$Read2 = 99.99 - $Read2
GUICtrlSetData($Button1, $Read2)
$RW = 2
 EndFunc

 

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