Jump to content
Sign in to follow this  
Maffe811

Reaction test

Recommended Posts

Maffe811

I couldn't figure out how to make the rectangle clickable so i just made a button.

Im planning to make it write to a history/log thing so you can see if you improove your reaction times.

I have a problem, wich im gonna figure out how to fix, but if you click while its blue, nothing happens.

Im gonna make it cancel it if you do that.

I also have a bug, if you click the button while it's blue then wait until it turns red it will accept the click at a random time.

So if I click it when its blue, then movethe mouse, I sometimes get 0.1 seconds and sometimes 1.7 seconds, and I don't know why.

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



Opt("MustDeclareVars", 1)

Global $Green = 0x00FF00
Global $Red = 0xFF0000
Global $Blue = 0x0000FF

Global $Gui, $Rect, $Button, $TimerStart, $TimerEnd, $Label

$Gui = GUICreate("", 400, 300)
$Rect = GUICtrlCreateGraphic(0, 0, 400, 200)
$Button = GUICtrlCreateButton("Start", 100, 210, 200, 40);260
$Label = GUICtrlCreateLabel("0.0", 0, 260, 400, 280, $ES_CENTER)

Func _Color($Color)
    ;Any color
    GUICtrlSetGraphic($Rect, $GUI_GR_COLOR, $Color, $Color)
    GUICtrlSetGraphic($Rect, $GUI_GR_RECT, 0, 0, 500, 200)
    GUICtrlSetGraphic($Rect, $GUI_GR_REFRESH)
EndFunc   ;==>_Color

GUISetState()

_Color($Green)

Global $Timer

Func _ButtonPress()
    If GUICtrlRead($Button) = "Start" Then
        GUICtrlSetData($Button, "Stop")
        _Color($Blue)
        Sleep(Random(1, 5000))
        _Color($Red)
        $TimerStart = TimerInit()
    ElseIf GUICtrlRead($Button) = "Stop" Then
        $TimerEnd = TimerDiff($TimerStart)
        GUICtrlSetData($Button, "Start")
        GUICtrlSetData($Label, Round($TimerEnd) / 1000 & " seconds")
        ConsoleWrite(Round($TimerEnd) / 1000 & " seconds")
;~      MsgBox("", "", Round($TimerEnd) / 1000 & " seconds")
        _Color($Green)
    EndIf
EndFunc   ;==>_ButtonPress

While 1
    Switch GUIGetMsg()
        Case $Button
            ConsoleWrite(GUICtrlRead($Button) & @CRLF)
            _ButtonPress()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
wakillon

I modified it a bit.

Now rectangle is clickable ! Posted Image

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

Opt("MustDeclareVars", 1)

Global $Green = 0x00FF00
Global $Red = 0xFF0000
Global $Blue = 0x0000FF
Global $Gui, $Rect, $Button, $TimerStart, $TimerEnd, $Label
Global $Timer, $_LabelColor, $_CursorInfo, $_Play=0, $_Time, $_TimeOld=100

$Gui = GUICreate("", 400, 300)
$Rect = GUICtrlCreateLabel ( '', 0, 0, 400, 200, 0x01 )
GUICtrlSetFont ( -1, 80, 800 )
$Button = GUICtrlCreateButton("Start Game", 100, 210, 200, 40);260
$Label = GUICtrlCreateLabel("0.0", 0, 260, 400, 280, $ES_CENTER)
_Color($Green)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $Button
            _ButtonPress()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If $_Play Then
        $_CursorInfo = GUIGetCursorInfo ( $Gui )
        If $_CursorInfo[2] And $_CursorInfo[4] = $Rect Then
            Switch $_LabelColor
                Case $Red
                    $TimerEnd = TimerDiff($TimerStart)
                    $_Time = Round ( $TimerEnd ) / 1000
                    If $_Time < $_TimeOld Then $_TimeOld = $_Time
                    GUICtrlSetData ( $Label, $_Time & " seconds" & @CRLF & 'Player record : ' & $_TimeOld )
                    _Color($Green)
                Case $Green
                    _Play ( )
            EndSwitch
        EndIf
    EndIf
WEnd

Func _Color($Color)
    Switch $Color
        Case $Blue
            GUICtrlSetData ( $Rect, 'Wait' )
        Case $Red
            GUICtrlSetData ( $Rect, 'Click' )
        Case Else
            GUICtrlSetData ( $Rect, 'Ready?' )
    EndSwitch
    GUICtrlSetBkColor ( $Rect, $Color)
    $_LabelColor = $Color
EndFunc   ;==>_Color

Func _ButtonPress()
    Switch  GUICtrlRead($Button)
        Case "Start Game"
            GUICtrlSetData($Button, "Stop Game")
            _Play ( )
        Case "Stop Game"
            GUICtrlSetData($Button, "Start Game")
            _Color($Green)
            GUICtrlSetData ( $Rect, 'Ready?' )
    EndSwitch
    $_Play = Not $_Play
EndFunc   ;==>_ButtonPress

Func _Play ( )
    GUICtrlSetState ( $Button, $GUI_DISABLE )
    _Color($Blue)
    Sleep ( Random (1000, 6000, 1))
    GUICtrlSetState ( $Button, $GUI_ENABLE )
    _Color($Red)
    $TimerStart = TimerInit()
EndFunc
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
Maffe811

Cool!

Like the idea of a record label!


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
wakillon

Cool!

Like the idea of a record label!

Thanks !

Posted Image

What's your score ?Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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  

×