Leaderboard
Popular Content
Showing content with the highest reputation on 02/21/2018 in all areas
-
Beated my own expectation down to 3 lines and shortened in bytes (using the $fcBtn makes it shorter could have made it $f offcourse but goal was not to obfuscate) local $fcBtn=GUICtrlCreateButton, $j=0, $2=0, $amsg[]=[0,0,0,0,0], $BA[] = ["7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", "="], $hGui = GUICreate("Calc", 360, 330, 229, 118), $f=GUISetFont(18, 400, 0, "MS Sans Serif"), $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetState(@SW_SHOW),$2 = $fcBtn($BA[0],7,50,65, 63) , $2 = $fcBtn($BA[1],77,50,65, 63) ,$2 = $fcBtn($BA[2],147,50,65, 63) ,$2 = $fcBtn($BA[3],217,50,65, 63) ,$2 = $fcBtn($BA[4],287,50,65, 63) ,$2 = $fcBtn($BA[5],7,120,65, 63) ,$2 = $fcBtn($BA[6],77,120,65, 63) ,$2 = $fcBtn($BA[7],147,120,65, 63) ,$2 = $fcBtn($BA[8],217,120,65, 63) ,$2 = $fcBtn($BA[9],287,120,65, 63) ,$2 = $fcBtn($BA[10],7,190,65, 63) ,$2 = $fcBtn($BA[11],77,190,65, 63) ,$2 = $fcBtn($BA[12],147,190,65, 63) ,$2 = $fcBtn($BA[13],217,190,65, 63) ,$2 = $fcBtn($BA[14],287,190,65, 63) ,$2 = $fcBtn($BA[15],7,260,65, 63) ,$2 = $fcBtn($BA[16],77,260,65, 63) ,$2 = $fcBtn($BA[17],147,260,65, 63) ,$2 = $fcBtn($BA[18],217,260,65, 63) ,$2 = $fcBtn($BA[19],287,260,65, 63) Do Until ((assign("aMsg",GUIGetMsg(1))=1) and ($aMsg[2]=0 ? $2=0 : (GUICtrlRead($aMsg[0]) = "C" ? GUICtrlSetData($D, "") : GUICtrlRead($aMsg[0]) = "SqRt" ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead($aMsg[0]) = "=" ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) : GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead($aMsg[0]))) and ($aMsg[0]=-3))=true) or ($aMsg[0] = -3) ; $GUI_EVENT_CLOSE I think I am out of tricks but maybe an MVP knows how to get it into a one liner2 points
-
Full GUI Calculator in under 40 lines
Gianni reacted to baroquebob for a topic
I've been experimenting with creating a simple GUI calculator (with actual buttons and display), in the fewest possible lines of code. So far, I'm at 38 lines (without white space). Unfortunately the script does not have any error handling, nor does it recognize numeric keypresses from the keyboard, but it otherwise seems to work okay. The code doesn't necessarily follow good programming practice, but I was just aiming for 'small'. Just sharing in case somebody else might find it interesting, and maybe would like to add error handling or keyboard input, (of course, following my minimalist approach. :-) ) Any thoughts on keeping the functionality as-is, but making the script even smaller? Opt("GUIOnEventMode", 1) DIM $BA[] = ["7","8","9","+","C","4","5","6","-","SqRt","1","2","3","*",".","0","(",")","/","="] Global $x = 8, $y = 50 GUICreate("Calc", 360, 330, 229, 118) $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080,2)) For $j = 0 to Ubound($BA) - 1 ;make the buttons btn($BA[$j]) Next GUISetState(@SW_SHOW) GUISetOnEvent(-3, "Bye") While 1 Sleep(25) ;Throttle WEnd Func btn($t) ;make button, associate event for each button press GUICtrlCreateButton($t, $x, $y, 65, 63) GUICtrlSetOnEvent(-1, "BP") GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $x += 70 If $x > 350 Then ;move down and left for next row of buttons $x = 8 $y += 70 EndIf EndFunc Func BP() ;handle the button press $v = GuiCtrlRead(@GUI_CtrlId) If $v = "C" Then GuiCtrlSetData($D, "") ElseIf $v = "SqRt" Then ;Solve expression, then take sqrt. GuiCtrlSetData($D, Sqrt(Execute(GuiCtrlRead($D)))) ElseIf $v = "=" Then ;solve the expression GuiCtrlSetData($D, Execute(GuiCtrlRead($D))) Else GuiCtrlSetData($D, GuiCtrlRead($D) & $v) EndIf EndFunc Func Bye() Exit EndFunc1 point -
@toto22 This code should works Local $iPid = WinGetProcess("TI Pro") Local $iAddress = 0x1FECD474 If $iPid = -1 Then ConsoleWrite("+++ Failed to get process PID. Open good process or change parameter in WinGetProcess func." & @CRLF) Exit EndIf Local $hHandle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', 1, 'int', $iPid) If @error Then ConsoleWrite("+++ Failed to open process memory for FULL_ACCESS. Error is " & @error & @CRLF) Exit EndIf Local $tagStruct = "struct;double var1;endstruct" Local $sStruct = DllStructCreate($tagStruct) If @error Then ConsoleWrite("+++ Failed to create $sStruct. Error is " & @error & @CRLF) Exit EndIf DllCall("kernel32.dll", 'int', 'ReadProcessMemory', 'int', $hHandle[0], 'int', $iAddress, 'ptr', DllStructGetPtr($sStruct), 'int', DllStructGetSize($sStruct), 'int', '') If @error Then ConsoleWrite("+++ Failed to Read Process Memory. Error is " & @error & @CRLF) Exit EndIf Local $vRet = DllStructGetData($sStruct, "var1") If @error Then ConsoleWrite("+++ Failed to Get data from $sStruct. Error is " & @error & @CRLF) Exit EndIf ConsoleWrite("++ Successfully read memory at addr 0x" & Hex($iAddress) & " value is " & $vRet & @CRLF)1 point
-
a 4 line version was also missing, here is one (... is few bytes less than the nice 3 lines version by @junkew) Global $iMsg, $j, $BA[] = [7, 8, 9, '+', 'C', 4, 5, 6, "-", "SqRt", 1, 2, 3, '*', '.', 0, '(', ')', '/', '='], $hGui = GUICreate('Calc', 360, 330, 229, 118, 0x00C00000), $D = GUICtrlCreateInput('', 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetState(@SW_SHOW), $a = DllCallbackRegister('BP', 'none', 'hwnd;uint;uint_ptr;dword'), $b = DllCall('user32.dll', 'uint_ptr', 'SetTimer', 'hwnd', 0, 'uint_ptr', 0, 'uint', 10, 'ptr', DllCallbackGetPtr($a)), $exit = MsgBox(0, "Info", "hit 'esc' or click here to exit"), $TheEnd1 = DllCallbackFree($a), $TheEnd2 = DllCall('user32.dll', 'bool', 'KillTimer', 'hwnd', 0, 'uint_ptr', $b) Func BP($hWnd, $iMsg2, $iTimerID, $iTime) ;handle the button press $j = (Assign('iMsg', GUIGetMsg(0))) * 0 ? 0 :($j < UBound($BA)) ?(GUICtrlCreateButton($BA[$j], Mod($j, 5) * 70 + 7, Int($j / 5) * 70 + 50, 65, 63) + GUICtrlSetFont(-1, 18, 400, 0, 'MS Sans Serif')) * 0 + $j + 1 : UBound($BA) + 0 * ($iMsg > 3 And $iMsg < 24 ?(GUICtrlRead($iMsg) = 'C' ? GUICtrlSetData($D, '') : GUICtrlRead($iMsg) = 'SqRt' ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead($iMsg) = '=' ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) :(StringInStr('0123456789()+-*/.', GUICtrlRead($iMsg))) > 0 ? GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead($iMsg)) : 0) : 20) EndFunc ;==>BP1 point
-
@toto22, There's a mistake in my previous post. The bit operations only work on 32 bit integers in AutoIt (no idea why). The below code shows a method using concatenation to build the hex string instead: ; Simulate the program $t = DllStructCreate("DOUBLE") DllStructSetData($t, 1, 123.456) $p = DllStructGetPtr($t) MsgBox(0, "Address", $p) ; This is what _MemoryRead($p) does the equivalent of $tRead = DllStructCreate("DWORD", $p) $hi = DllStructGetData($tRead, 1) ; This is what _MemoryRead($p+4) does the equivalent of $tRead = DllStructCreate("DWORD", $p+4) $lo = DllStructGetData($tRead, 1) ; Combine back into an 8byte integer: $full = Hex($lo,8) & Hex($hi,8) MsgBox(0, "Read from memory", "Two dwords:" & @CRLF & Hex($hi,8) & @CRLF & Hex($lo,8) & @CRLF & $full) ; Conversion to double: $sMemHex = String($full) $nNum = Dec($sMemHex, 3) MsgBox(0, $full, $nNum) I don't have NomadMemory installed, so instead I've shown the equivalent using structs (this method only works within one process).1 point
-
@NguyenLe Try making the following change to _WD_WaitElement -- If $iErr Then SetError(__WD_Error($sFuncName, $iErr)) EndIf Basically, by adding the If...EndIf, it stops __WD_Error for being called unless an error was previously detected.1 point
-
Use the <> in the menubar to post code. I highly doubt that line 21 is the issue. This piece of code is is wrong logic and can create a recursion level error as well: Func Install() ;~ Install Program Local $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup") If $CCHandle = 0x00000000 Then Sleep(1500) Install() EndIf Should be something like: (But still could be waiting forever so might want to put a limit to the wait time there) Func Install() ;~ Install Program Local $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup") While $CCHandle = 0x00000000 Then Sleep(1500) $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup") WEnd This code could be blocking as well as it is an endless wait: WinActivate($CCHandle, '') WinWaitActive($CCHandle, '') Just add a timer in the last line and test for that to trigger an error. Your other Func's have the same issue with the recursion and need to be changed as well. Jos1 point
-
@NguyenLe Ok, I see it now. I'll have to dig into it to see why this is occurring. As a temporary fix, you can set $_WD_ERROR_MSGBOX = False to prevent the message box from being displayed in the compiled app.1 point
-
12 lines: Local $0 = Opt("GUIOnEventMode", 1), $BA[] = ["7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", "="], $hGui = GUICreate("Calc", 360, 330, 229, 118), $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetOnEvent(-3, "Bye") * GUISetState(@SW_SHOW) For $j = 0 to UBound($BA) - 1 ;make the buttons $2 = GUICtrlCreateButton($BA[$j], Mod($j, 5) * 70 + 7, Int($j / 5) * 70 + 50, 65, 63) + GUICtrlSetOnEvent(-1, "BP") + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") Next While Sleep(100) ;Throttle WEnd Func BP() ;handle the button press $v = GUICtrlRead(@GUI_CtrlId) = "C" ? GUICtrlSetData($D, "") : GUICtrlRead(@GUI_CtrlId) = "SqRt" ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead(@GUI_CtrlId)= "=" ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) : GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead(@GUI_CtrlId)) EndFunc ;==>BP Func Bye() Exit EndFunc ;==>Bye1 point
-
https://www.autoitscript.com/autoit3/docs/libfunctions/_ScreenCapture_Capture.htm https://www.autoitscript.com/autoit3/docs/functions/Run.htm add some screencapture directly after your run($sCommand) hopefully you can catch the error then Run($sCommand) for $i=1 to 10 sleep(50) _ScreenCapture_Capture("check" & $i & ".jpg") next1 point