Jump to content

Recommended Posts

Posted

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

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, or

point me in the direction I would need to go to in order

to find what it is I'm looking for.

"You're not smart enough for me to open my inbox, so stop sending me mail."
Posted (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 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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Posted (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 by AutoitNew94
"You're not smart enough for me to open my inbox, so stop sending me mail."
Posted

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
Posted

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."
Posted (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 by AutoitNew94
"You're not smart enough for me to open my inbox, so stop sending me mail."

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...