AutoitNew94 Posted March 4, 2011 Share Posted March 4, 2011 Very basic general question here. How do I exit the below correctly? $fileOpen = FileOpen("test.txt", 1) While 1 If _IsPressed('30') = 1 Then FileWriteLine($fileOpen, "0") If _IsPressed('31') = 1 Then FileWriteLine($fileOpen, "1") Sleep(10) Wend Obviously the above produces output like so... 0 0 0 0 0 1 1 1 1 1 1 I don't care about wrapping the output as much, just want it to produce... 0 1 ...instead. Example Script is requested. Thank you. "You're not smart enough for me to open my inbox, so stop sending me mail." Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 4, 2011 Share Posted March 4, 2011 Keep the last result you got in a variable, and only output if the new result is different from the old one. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AutoitNew94 Posted March 4, 2011 Author Share Posted March 4, 2011 Keep the last result you got in a variable, and only output if the new result is different from the old one.Thank you for the reply Psalty.I am new to autoit, could you show me an example, orpoint me in the direction I would need to go to in orderto find what it is I'm looking for. "You're not smart enough for me to open my inbox, so stop sending me mail." Link to comment Share on other sites More sharing options...
guinness Posted March 4, 2011 Share Posted March 4, 2011 (edited) Example Script is requested.Doesn't work like that! #include <Misc.au3> $hFileOpen = FileOpen("Test.txt", 1) $iIsPressed = -1 While 1 If _IsPressed('30') = 1 And Not $iIsPressed = 0 Then ; 0 Key FileWriteLine($hFileOpen, "0") ConsoleWrite(0 & @CRLF) $iIsPressed = 0 ElseIf _IsPressed('31') = 1 And Not $iIsPressed = 1 Then ; 1 Key FileWriteLine($hFileOpen, "1") ConsoleWrite(1 & @CRLF) $iIsPressed = 1 EndIf Sleep(10) WEnd FileClose($hFileOpen) Edited March 4, 2011 by guinness UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
AutoitNew94 Posted March 4, 2011 Author Share Posted March 4, 2011 (edited) Doesn't work like that! Yes Guinness that is what I was trying to get at. Perhaps a casual dress code could be acquired for this thread. Maybe I should have just hooked it in c nah no fun in that. O_o Of course though with this method adding more of these ElseIf statements doesn't pickup what it is suppose to. Func _IsPressed($hexKey) Local $aR, $bO $hexKey = '0x' & $hexKey $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey) If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then $bO = 1 Else $bO = 0 EndIf Return $bO EndFunc ;==>_IsPressed Will adding the above function combat this issue? Edited March 4, 2011 by AutoitNew94 "You're not smart enough for me to open my inbox, so stop sending me mail." Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 4, 2011 Share Posted March 4, 2011 I meant something like this: #include <Misc.au3> HotKeySet("{ESC}", "_Quit") Global $sLast = "" While 1 If _IsPressed('30') Then If $sLast <> "30" Then ConsoleWrite("Pressed: 30" & @LF) $sLast = "30" EndIf If _IsPressed('31') Then If $sLast <> "31" Then ConsoleWrite("Pressed: 31" & @LF) $sLast = "31" EndIf Sleep(20) WEnd Func _Quit() Exit EndFunc ;==>_Quit Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AutoitNew94 Posted March 4, 2011 Author Share Posted March 4, 2011 I meant something like this: #include <Misc.au3> HotKeySet("{ESC}", "_Quit") Global $sLast = "" While 1 If _IsPressed('30') Then If $sLast <> "30" Then ConsoleWrite("Pressed: 30" & @LF) $sLast = "30" EndIf If _IsPressed('31') Then If $sLast <> "31" Then ConsoleWrite("Pressed: 31" & @LF) $sLast = "31" EndIf Sleep(20) WEnd Func _Quit() Exit EndFunc ;==>_Quit Thanks Psalty works well if I replace the misc.au3 with... Func _IsPressed($HexKey) Local $aR, $bO $aR = DllCall($OpenDll, "int", "GetAsyncKeyState", "int", $HexKey & $CloseDll) If $aR[0] <> 0 Then $bO = 1 Else $bO = 0 EndIf Return $bO EndFunc ...and replace the ConsoleWrite with a user function. Yeah this is getting me closer to the end result. "You're not smart enough for me to open my inbox, so stop sending me mail." Link to comment Share on other sites More sharing options...
AutoitNew94 Posted March 4, 2011 Author Share Posted March 4, 2011 (edited) So, I modified it a bit and came up with... #Include <misc.au3> HotKeySet("{ESC}", "_Quit") Global $sLast = "" $FileOpen = FileOpen("Test.txt", 1) While 1 If _IsPressed('30') Then If $sLast <> "30" Then FileWriteLine($FileOpen, "0" & @LF) $sLast = "30" EndIf If _IsPressed('31') Then If $sLast <> "31" Then FileWriteLine($FileOpen, "1" & @LF) $sLast = "31" EndIf If _IsPressed('32') Then If $sLast <> "32" Then FileWriteLine($FileOpen, "2" & @LF) $sLast = "32" EndIf Sleep(20) WEnd Func _Quit() Exit EndFunc ;==>_Quit ...Now how would I combine this function to replace the misc.au3 for the hex values, and or would it be easier to create a bunch of hotkey sets with appended actions. Func _IsPressed($HexKey) Local $aR, $bO $aR = DllCall($OpenDll, "int", "GetAsyncKeyState", "int", $HexKey & $CloseDll) If $aR[0] <> 0 Then $bO = 1 Else $bO = 0 EndIf Return $bO EndFunc Edited March 4, 2011 by AutoitNew94 "You're not smart enough for me to open my inbox, so stop sending me mail." 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