Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/02/2013 in all areas

  1. Don't be ashamed to have something to learn! EDIT: this version tests for the Null keyword introduced in the beta. Comment out the relevant part for running under the latest release. (I recommend the beta anyway.) You can try this for displaying type and contents of a variable or array: Local $arr0[1] = ['arrayTest'] Local $arr1[9] = [5, 4.5, 0x2, '0x2', 'hello world', Binary('0x2'), -8, '0x0nothex', $arr0] ConsoleWrite(_VarDump($arr0) & @LF & @LF) ConsoleWrite(_VarDump($arr1) & @LF) Func _VarDump(ByRef $vVar, $sIndent = '') Local $ret, $len Select Case IsDllStruct($vVar) $len = DllStructGetSize($vVar) Local $bstruct = DllStructCreate("byte[" & $len & "]", DllStructGetPtr($vVar)) $ret = 'Struct(' & $len & ') @:' & Hex(DllStructGetPtr($vVar)) & ' = ' If $len <= 32 Then Return ($ret & DllStructGetData($bstruct, 1)) Else Return ($ret & BinaryMid(DllStructGetData($bstruct, 1), 1, 16) & ' ... ' & StringTrimLeft(BinaryMid(DllStructGetData($bstruct, 1), $len - 15, 16), 2)) EndIf Case IsArray($vVar) Local $iSubscripts = UBound($vVar, 0) Local $sDims = 'Array' $iSubscripts -= 1 For $i = 0 To $iSubscripts $sDims &= '[' & UBound($vVar, $i + 1) & ']' Next Return $sDims & @CRLF & _VarDumpArray($vVar, $sIndent) Case IsBinary($vVar) $len = BinaryLen($vVar) $ret = 'Binary(' & BinaryLen($vVar) & ') = ' If $len <= 32 Then Return ($ret & $vVar) Else Return ($ret & BinaryMid($vVar, 1, 16) & ' ... ' & StringTrimLeft(BinaryMid($vVar, $len - 15, 16), 2)) EndIf Case IsBool($vVar) Return 'Boolean ' & $vVar Case IsFloat($vVar) Or (IsInt($vVar) And VarGetType($vVar) = "Double") Return 'Double ' & $vVar Case IsHWnd($vVar) Return 'HWnd ' & $vVar Case IsInt($vVar) Return "Integer(" & StringRight(VarGetType($vVar), 2) & ') ' & $vVar Case IsKeyword($vVar) $ret = 'Keyword ' If $vVar = Null Then Return $ret & 'Null' Else Return $ret & $vVar EndIf Case IsPtr($vVar) Return 'Pointer @:' & StringTrimLeft($vVar, 2) Case IsObj($vVar) Return 'Object ' & ObjName($vVar) Case IsString($vVar) $len = StringLen($vVar) $ret = 'String(' & $len & ") " If StringRegExp($vVar, "[\x00-\x1F\x7F-\x9F]") Then If $len <= 64 Then Return $ret & _DumpStringWithControlChars($vVar) Else Return ($ret & StringMid(_DumpStringWithControlChars($vVar), 1, 32) & ' ... ' & StringTrimLeft(StringMid(_DumpStringWithControlChars($vVar), $len - 31, 32), 2)) EndIf Else If $len <= 64 Then Return $ret & "'" & $vVar & "'" Else Return ($ret & "'" & StringMid($vVar, 1, 32) & ' ... ' & StringTrimLeft(StringMid($vVar, $len - 31, 32), 2)) & "'" EndIf EndIf Case Else Return 'Unknown ' & $vVar EndSelect EndFunc ;==>_VarDump Func _VarDumpArray(ByRef $aArray, $sIndent = @TAB) Local $sDump Local $sArrayFetch, $sArrayRead, $bDone Local $iSubscripts = UBound($aArray, 0) Local $aUBounds[$iSubscripts] Local $aCounts[$iSubscripts] $iSubscripts -= 1 For $i = 0 To $iSubscripts $aUBounds[$i] = UBound($aArray, $i + 1) - 1 $aCounts[$i] = 0 Next $sIndent &= @TAB While 1 $bDone = True $sArrayFetch = '' For $i = 0 To $iSubscripts $sArrayFetch &= '[' & $aCounts[$i] & ']' If $aCounts[$i] < $aUBounds[$i] Then $bDone = False Next $sArrayRead = Execute('$aArray' & $sArrayFetch) If @error Then ExitLoop Else $sDump &= $sIndent & $sArrayFetch & ' => ' & _VarDump($sArrayRead, $sIndent) If Not $bDone Then $sDump &= @CRLF Else Return $sDump EndIf EndIf For $i = $iSubscripts To 0 Step -1 $aCounts[$i] += 1 If $aCounts[$i] > $aUBounds[$i] Then $aCounts[$i] = 0 Else ExitLoop EndIf Next WEnd EndFunc ;==>_VarDumpArray Func _DumpStringWithControlChars(ByRef $sStr) Local $sDump Local $aCh = StringToASCIIArray($sStr) Local $bInStr = False For $ch In $aCh Switch $ch Case 0 To 0x1F, 0x7F To 0x9F If $bInStr Then $bInStr = False $sDump &= "'" EndIf $sDump &= " 0x" & Hex($ch, 2) & " " Case Else If Not $bInStr Then $bInStr = True $sDump &= "'" EndIf $sDump &= ChrW($ch) EndSwitch Next If $bInStr Then $sDump &= "'" Return ($sDump) EndFunc ;==>_DumpStringWithControlChars
    1 point
  2. water

    Need easy help

    BTW: Could you please give your threads a meaningful title Everyone on the General Help and Support forum is seeking for help. So "Need easy help" doesn't tell us what you are looking for!
    1 point
  3. Here's my modified code: Func _CheckPort($vPort = 7337) TCPStartup() $MainSocket = TCPListen('0.0.0.0', $vPort) FileDelete(@ScriptDir & "\port.dat") Local $hDownload, $go = 1 Do Local $ConnectedSocket = TCPAccept($MainSocket) If $ConnectedSocket >= 0 Then TCPSend($connectedsocket, "Cool Story Bro") EndIf Sleep(5) if $go = 1 then $hDownload = InetGet("http://prodynamicsinc.com/link.php?CMD=page&ID=portcheck&buffer=0&port=" & $vPort&"&IP="&_GetIP(), @ScriptDir & "\port.dat", 1, 1) $go = 0 EndIf Until InetGetInfo($hDownload, 2) local $portcheck = FileRead(@ScriptDir & "\port.dat") FileDelete(@ScriptDir & "\port.dat") InetClose($hDownload) TCPShutdown() If $portcheck = "Port Open" Then Return True Else Return False EndIf EndFunc and the sourcecode of the php page: <?PHP echo getserverstatus($_GET['IP'],$_GET['port']); die(); function GetServerStatus($site, $port) { $status = array("Port Not Open", "Port Open"); $fp = @fsockopen($site, $port, $errno, $errstr, 2); if (!$fp) { return $status[0]; } else { return $status[1];} } ?> Cheers. Edit: Edited function to allow listening on incoming socket, and response, while awaiting a response on status of the port being checked. Edit Edit: It still doesn't seem to work, it works for ports opened by other applications, but for some reason it's not letting me check if a port has been opened within the same script.... Edit Edit Edit: Nevermind on that last, seems to work perfect, the port I had defaulted was out of range.
    1 point
  4. Detefon, As others have already said in substance, you are confusing two distinct notions: the computer/language type of a variable (or a literal value) and its visual representation. 0x20 is the typical representation in hexadecimal (base 16) of the integral value 32 in decimal (base 10) and 00100000 is its representation in base 2. When displayed or printed, this value can become the strings "0x20" or "32" or "00100000" after conversion. You and me are commonly representing integers in decimal just because we happen by chance to have 10 fingers. Should we have only one arm with six fingers, we would probably count in base six, hence 0x20 would be 52 and we would never have imagined a glyph like 6 to represent 10 (in base six). Beyond visual representation (= nothing more than a convention for display or print), values in a computer are stored according to a type. Every language offers its own set of types to store different things. The string "Defeton" is nowhere close to an integer and 32 is an integral quantity stored as Int just like 0x20. Floating point values are completely different beasts using a special type to hold [a very small number of] numerical values having an optional fractional part. Binary type, in the AutoIt context, is a type able to store a length of raw bytes and has nothing to do with representation in base 2.
    1 point
  5. Jos

    Need easy help

    Are you sure? maybe look again...
    1 point
  6. DW1

    Need easy help

    It was curly brackets in the video as well, just hard to see it. The sleep is there because we have an infinite loop. I think autoit does a good job of not killing the CPU even without it there, but lets say for example that we are doing a basic calculation in that loop. Now we are using the processor to do a basic calculation and as soon as it's done, do it again, rinse and repeat. With no sleep in an infinite loop that does a basic calculation, we would expect one full core to get utilized because it is doing exactly what we told it to; do this as fast as you can, over and over. With the sleep, we guarantee that we are not trying to run this as fast as possible and freeing up processor time for other programs.
    1 point
  7. DW1

    Need easy help

    A few things wrong here. First, the reason it isn't working at all is because "(up)" should be "{up}". Note the curly brackets. The rest of the arrow keys should also use curly brackets. Now the script should be working, but not correctly... you'll notice the mouse moves in unexpected ways. This is because you have confused $pos[1] vs $pos[0] in both the left and right functions. HotKeySet("{UP}", "up") HotKeySet("{DOWN}", "down") HotKeySet("{RIGHT}", "right") HotKeySet("{LEFT}", "left") While 1 Sleep(10) WEnd Func up() $pos = MouseGetPos() MouseMove($pos[0], $pos[1] - 1, 1) EndFunc ;==>up Func down() $pos = MouseGetPos() MouseMove($pos[0], $pos[1] + 1, 1) EndFunc ;==>down Func right() $pos = MouseGetPos() MouseMove($pos[0] + 1, $pos[1], 1) EndFunc ;==>right Func left() $pos = MouseGetPos() MouseMove($pos[0] - 1, $pos[1], 1) EndFunc ;==>left
    1 point
  8. Binary, Hex and integers can all be integers, Binary and Hex are just different ways of presenting the same numbers in a different format.
    1 point
  9. if you perform any string operation with a integer Autoit would convert it to a string and vice-versa (casting of data types) $mySerial = Random(1,1000000,1) & "" If IsString($mySerial) Then ConsoleWrite("String: " & $mySerial) Else ConsoleWrite("Not String: " & $mySerial) EndIf
    1 point
  10. Hi, 0x020 is a hexadecimal number, not a binary. Do it this way : Local $arr[3] = [1, 1.5, Binary("0x020")] For $each In $arr ConsoleWrite('[' & $each & '][' & numType($each) & ']' & @LF) Next Func numType($input) Select Case IsFloat($input) Return 'Float' Case IsInt($input) Return 'Int' Case IsBinary($input) Return 'Binary' EndSelect EndFunc ;==>numTypeEdit: Added indents. Br, FireFox.
    1 point
  11. Have a look #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> GUICreate("", 300, 450) Local $listView = GUICtrlCreateListView("A|B|C|D|E|F|G", 25, 25, 250, 400, -1, $LVS_EX_GRIDLINES) For $i = 0 To 20 GUICtrlCreateListViewItem("A" & $i & "|B" & $i & "|C" & $i & "|D" & $i & "|E" & $i & "|F" & $i & "|G" & $i, $listView) Next $listView = GUICtrlGetHandle($listView) ;the example didn't work when used with ControlID. ;lets do it by handling the primary down event. GUISetState() Local $nMsg, $aInfo Do $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_PRIMARYDOWN $s_Item = GetItemClicked($listView) If @error = 0 Then ConsoleWrite($s_Item & ": was clicked" & @CRLF) EndSwitch Until $nMsg = $GUI_EVENT_CLOSE Func GetItemClicked( $hListView ) ;get the info $aInfo = _GUICtrlListView_SubItemHitTest( $hlistView ) If $aInfo[0] = -1 Or $aInfo[1] = -1 Then Return SetError(2, 0, -1) If IsArray($aInfo) = 0 Then Return SetError(1, 0, -1) ;get the item/subitem text. Return _GUICtrlListView_GetItemText($hlistView, $aInfo[0], $aInfo[1]) EndFunc Regards
    1 point
  12. Do you have the full version of Scite4Autoit3 installed? Because those won't work without the full install of Scite, the lite version won't help.
    1 point
  13. That wont work as you are still testing from behind your internal router. Try this. Func _CheckPort($vPort = 80) $vUrl = InetRead("http://flibware.com/port.php?port=" & $vPort) $vCheckPort = StringRegExp(BinaryToString($vUrl), "<body>(.*?)</body></html>", 3) If $vCheckPort[0] = "Port Open" Then Return True Else Return False EndIf EndFunc This will test from a remote website
    1 point
  14. LarsJ

    OpenGL GlReadPixels

    I use this code for a screen dump of an OpenGL window: Local Static $iDump = 0 If $iDump = 0 Then Local $tBuffer = DllStructCreate( "byte[" & $iWidth * $iHeight * 3 & "]" ) glReadPixels( 0, 0, $iWidth, $iHeight, $GL_RGB, $GL_UNSIGNED_BYTE, DllStructGetPtr( $tBuffer ) ) Local $hFile = FileOpen( "image.data", 18 ) FileWrite( $hFile, DllStructGetData( $tBuffer, 1 ) ) FileClose( $hFile ) $iDump = 1 EndIf I just add the code to the display function. The raw RGB/RGBA image file "image.data" can be opened with GIMP (the extension must be "data").
    1 point
  15. LarsJ

    OpenGL GlReadPixels

    Hi Tomb, I've just seen your message (I'm not logged on every day) and this problem. I think your code looks fine, but I'm pretty sure that "glReadpixels" in the DllCall is with a capital p: "glReadPixels". And I do think that matters. (I see now that you have a capital p in the first function.) This function works for me: Func glReadPixels($x, $y, $width, $height, $format, $type, $pixels) DllCall("opengl32.dll", "none", "glReadPixels", "int", $x, "int", $y, "int", $width, "int", $height, "uint", $format, "uint", $type, "ptr", $pixels) If @error Then MsgBox( 0, "glReadPixels", "Error" ) EndFunc Regards Lars.
    1 point
  16. Notable mention is using prefix to indicate the type of expected variable. . $aStuff ;array $sStuff ;string $oStuff; object $hStuff; handle $bStuff ; binary, true/false $iStuff ; integer $nStuff ;number $g*stuff ; global variable $c*stuff ; constant If there is a more complete list, a link would be appreciated. I think there is a name for that syntax after some old school programmer, but for the life of me can't remember. I used to be really bad at doing that, and still revert to bad syntax when throwing out examples. I don't know what is a normal prefix for static, I never saw that keyword before perusing this thread. At first I didn't even get why people put those prefixes in, then once I got it I thought it would slow me down. Now I can't see myself doing anything halfway serious without it.
    1 point
×
×
  • Create New...