billthecreator Posted January 23, 2010 Share Posted January 23, 2010 (edited) im creating a typing game... and im afraid i dont know how to detect key input when its not the one im looking for. lets say i have "J" up, and you're supposed to press "J", the _IsPressed() for "J" is "4A". i have it so when its clicked, points are added. how would i have it so, if any other keys are hit, a function is done. i had it so the if/then _ispressed statement is called, the else of subtracting points would not work when only keys are pressed, it would work on an infinite loop. heres some code... expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> Global $letters[26][2]= [["A", "41"], _ ["B", "42"], _ ["C", "43"], _ ["D", "44"], _ ["E", "45"], _ ["F", "46"], _ ["G", "47"], _ ["H", "48"], _ ["I", "49"], _ ["J", "4A"], _ ["K", "4B"], _ ["L", "4C"], _ ["M", "4D"], _ ["N", "4E"], _ ["O", "4F"], _ ["P", "50"], _ ["Q", "51"], _ ["R", "52"], _ ["S", "53"], _ ["T", "54"], _ ["U", "55"], _ ["V", "56"], _ ["W", "57"], _ ["X", "58"], _ ["Y", "59"], _ ["Z", "5A"]] #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 400, 257, 391, 206) $Label1 = GUICtrlCreateLabel("", 20, 72, 360, 82, $SS_CENTER) GUICtrlSetFont(-1, 52, 400, 0, "Arial Narrow") GUICtrlSetColor(-1, 0x008a00) $Label2 = GUICtrlCreateLabel("Score:", 8, 8, 35, 17) $Label3 = GUICtrlCreateLabel("Time Left:", 8, 232, 51, 17) $Button1 = GUICtrlCreateButton("Start", 320, 192, 75, 25, $WS_GROUP) $Button2 = GUICtrlCreateButton("Stop", 320, 224, 75, 25, $WS_GROUP) $Label4 = GUICtrlCreateLabel("", 56, 8, 76, 17) $Label6 = GUICtrlCreateLabel("", 56, 25, 76, 17) $Label5 = GUICtrlCreateLabel("7 second(s)", 64, 232, 70, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $dll = DllOpen("user32.dll") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _StartTyping() EndSwitch WEnd Func _StartTyping() While 1 $randomeletter = Random(0, 25, 1) GUICtrlSetData($Label1, $letters[$randomeletter][0]) $timer = TimerInit() While TimerDiff($timer) < 7000 GUICtrlSetData($Label5, Round((7000-TimerDiff($timer))/1000, 0) & " second(s)") Sleep(62) If GUIGetMsg() = $Button2 Then ExitLoop 2 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit If _IsPressed($letters[$randomeletter][1],$dll) Then GUICtrlSetData($Label4, GUICtrlRead($Label4) + Round((7000-TimerDiff($timer))/1000, 0)*25) GUICtrlSetData($Label6, "+ " & Round((7000-TimerDiff($timer))/1000, 0)*25) ExitLoop 1 EndIf ; this is when you click the wrong key. ;~ GUICtrlSetData($Label4, GUICtrlRead($Label4) - Round((7000-TimerDiff($timer))/1000, 0)*25) ;~ GUICtrlSetData($Label6, "- " & Round((7000-TimerDiff($timer))/1000, 0)*25) WEnd WEnd EndFunc Edited January 23, 2010 by billthecreator [font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap Link to comment Share on other sites More sharing options...
Yashied Posted January 23, 2010 Share Posted January 23, 2010 expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> Global $letters[26][2] = [["A", "41"], _ ["B", "42"], _ ["C", "43"], _ ["D", "44"], _ ["E", "45"], _ ["F", "46"], _ ["G", "47"], _ ["H", "48"], _ ["I", "49"], _ ["J", "4A"], _ ["K", "4B"], _ ["L", "4C"], _ ["M", "4D"], _ ["N", "4E"], _ ["O", "4F"], _ ["P", "50"], _ ["Q", "51"], _ ["R", "52"], _ ["S", "53"], _ ["T", "54"], _ ["U", "55"], _ ["V", "56"], _ ["W", "57"], _ ["X", "58"], _ ["Y", "59"], _ ["Z", "5A"]] #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 400, 257, 391, 206) $Label1 = GUICtrlCreateLabel("", 20, 72, 360, 82, $SS_CENTER) GUICtrlSetFont(-1, 52, 400, 0, "Arial Narrow") GUICtrlSetColor(-1, 0x008a00) $Label2 = GUICtrlCreateLabel("Score:", 8, 8, 35, 17) $Label3 = GUICtrlCreateLabel("Time Left:", 8, 232, 51, 17) $Button1 = GUICtrlCreateButton("Start", 320, 192, 75, 25, $WS_GROUP) $Button2 = GUICtrlCreateButton("Stop", 320, 224, 75, 25, $WS_GROUP) $Label4 = GUICtrlCreateLabel("", 56, 8, 76, 17) $Label6 = GUICtrlCreateLabel("", 56, 25, 76, 17) $Label5 = GUICtrlCreateLabel("7 second(s)", 64, 232, 70, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _StartTyping() EndSwitch WEnd Func _StartTyping() While 1 $randomeletter = Random(0, 25, 1) GUICtrlSetData($Label1, $letters[$randomeletter][0]) $timer = TimerInit() While TimerDiff($timer) < 7000 GUICtrlSetData($Label5, Round((7000 - TimerDiff($timer)) / 1000, 0) & " second(s)") Sleep(62) If GUIGetMsg() = $Button2 Then ExitLoop 2 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit If _IsPressed($letters[$randomeletter][1]) Then While _AnyPressed() Sleep(10) WEnd GUICtrlSetData($Label4, GUICtrlRead($Label4) + Round((7000 - TimerDiff($timer)) / 1000, 0) * 25) GUICtrlSetData($Label6, "+ " & Round((7000 - TimerDiff($timer)) / 1000, 0) * 25) ExitLoop Else If _AnyPressed() Then While _AnyPressed() Sleep(10) WEnd GUICtrlSetData($Label4, GUICtrlRead($Label4) - Round((7000 - TimerDiff($timer)) / 1000, 0) * 25) GUICtrlSetData($Label6, "- " & Round((7000 - TimerDiff($timer)) / 1000, 0) * 25) ExitLoop EndIf EndIf WEnd WEnd EndFunc ;==>_StartTyping Func _AnyPressed() For $i = 0 To UBound($letters) - 1 If _IsPressed($letters[$i][1]) Then Return 1 EndIf Next Return 0 EndFunc ;==>_AnyPressed My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
billthecreator Posted January 23, 2010 Author Share Posted January 23, 2010 that's great. thank you so much. i had a feeling it would have been this easy. but thank you! [font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now