Search found 338 matches

by pneumatic
05 May 2021, 22:33
Forum: Ask for Help (v1)
Topic: Array key unexpectedly converted to int Topic is solved
Replies: 2
Views: 295

Re: Array key unexpectedly converted to int Topic is solved

Oh it seems appending "" to the keys during the push() fixes it.

(but Format("{:s}") doesn't)

Nevermind.
by pneumatic
05 May 2021, 22:27
Forum: Ask for Help (v1)
Topic: Array key unexpectedly converted to int Topic is solved
Replies: 2
Views: 295

Array key unexpectedly converted to int Topic is solved

For some reason AHK appears to be interpreting one of my array keys as an integer despite being a string: keys := ["0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01" ,"01234567890123456789012345678901234567890123456789"] a := [] a.push( {keys[1] : "value1"} ) a.push( {keys[2] : "value2"} ) loop % ...
by pneumatic
05 May 2021, 19:37
Forum: Ask for Help (v1)
Topic: Search optimisation Topic is solved
Replies: 42
Views: 4055

Re: Search optimisation Topic is solved

teadrinker wrote:
05 May 2021, 19:28
I edited my post, simplified the code a bit. :)
It's significantly faster, but worse for noobs like me who want to do other stuff inside the while loop like update a progress bar or something.
by pneumatic
05 May 2021, 19:08
Forum: Ask for Help (v1)
Topic: Search optimisation Topic is solved
Replies: 42
Views: 4055

Re: Search optimisation Topic is solved

Incredible solutions, thank you very much.

It's a close call, but I would have to favour teadrinker's solution as it supports 64-bit and is a bit more orthodox.

Apart from that the mcode solution is very cool; AHK is amazing!
by pneumatic
04 May 2021, 22:30
Forum: Ask for Help (v1)
Topic: Efficiently read file into byte array Topic is solved
Replies: 10
Views: 1294

Re: Efficiently read file into byte array Topic is solved

Just for completeness, I found that FileRead with the *C option is about twice as fast as reading it into a ComObjArray. Then using NumGet to retrieve the values.
by pneumatic
04 May 2021, 22:08
Forum: Ask for Help (v1)
Topic: Search optimisation Topic is solved
Replies: 42
Views: 4055

Re: Search optimisation Topic is solved

I'm still not confident that linear search implemented with mcode would be similarly fast to hex editors such as HxD, simply because of how CPU hungry linear search is. Perhaps there is some other optimisation technique using bitwise operations? One idea is that since a byte can only have 256 differ...
by pneumatic
04 May 2021, 20:58
Forum: Ask for Help (v1)
Topic: Search optimisation Topic is solved
Replies: 42
Views: 4055

Search optimisation Topic is solved

Hello I am trying to search a 7MB binary file for a few byte patterns, similar to using a search function in a typical hex editor program. I am able to implement this in AHK with a naive search algorithm ('linear search') in conjunction with FileRead *C and NumGet UChar. Being linear search it is ob...
by pneumatic
15 Apr 2021, 14:23
Forum: Ask for Help (v1)
Topic: RTrim not removing carriage returns
Replies: 4
Views: 280

Re: RTrim not removing carriage returns

You haven't assigned the result to anything. Needs to be: string := RTrim(string, "`r`n") The same thing would have happened if you just had your StrReplace call "floating" like that. Apologies, that was just a syntax error. The issue ended up being that I was using RTrim on an entire file contents...
by pneumatic
15 Apr 2021, 14:06
Forum: Ask for Help (v1)
Topic: RTrim not removing carriage returns
Replies: 4
Views: 280

RTrim not removing carriage returns

Code: Select all

string := "abc`r`n"
RTrim(string, "`r`n")
msgbox % "StrLen(string): " . StrLen(string) ;5
string := StrReplace(string, "`r")
msgbox % "StrLen(string): " . StrLen(string) ;4
What am I doing wrong?
by pneumatic
15 Apr 2021, 08:28
Forum: Ask for Help (v1)
Topic: Are string comparisons short-circuited? Topic is solved
Replies: 1
Views: 134

Are string comparisons short-circuited? Topic is solved

abc := "abc" , def := "def" if (abc = def) ;short circuit? In this case, will AHK compare each and every character in abc with def, or will it start by comparing, say, "a" with "d", see that it's not equal, and exit the comparison loop since if the two first characters don't match the whole strings...
by pneumatic
13 Apr 2021, 16:34
Forum: Ask for Help (v1)
Topic: Overwrite a single byte in a file Topic is solved
Replies: 2
Views: 267

Re: Overwrite a single byte in a file Topic is solved

I'd suggest you learning the basics before deal with raw hex data, this may be dangerous! ;) w    Write: Creates a new file, overwriting any existing file . You need at least using "rw". Although your method will work with "rw", more suitable way is: file := FileOpen("myfile.txt", "rw") file.Pos :=...
by pneumatic
13 Apr 2021, 14:08
Forum: Ask for Help (v1)
Topic: Overwrite a single byte in a file Topic is solved
Replies: 2
Views: 267

Overwrite a single byte in a file Topic is solved

As per the title, is this possible in Autohotkey? I've been trying for hours with VarSetCapacity , NumPut and RawWrite to no avail. I have a very small test file which contains 46 bytes: https://i1.lensdump.com/i/IMmBdr.png I would like to write, say, 0xFF to the cell at offset 0x0A. i.e the value 0...
by pneumatic
13 Apr 2021, 05:05
Forum: Ask for Help (v1)
Topic: Efficiently read file into byte array Topic is solved
Replies: 10
Views: 1294

Re: Efficiently read file into byte array Topic is solved

Ok now it's working, no need for the percent signs.
by pneumatic
13 Apr 2021, 05:02
Forum: Ask for Help (v1)
Topic: Efficiently read file into byte array Topic is solved
Replies: 10
Views: 1294

Re: Efficiently read file into byte array Topic is solved

Code: Select all

filebytes := ComObjArray(VT_UI1 := 0x11, 8)

;works -- says looped 8 times
loop % filebytes.maxindex()+1
	count++
msgbox % "looped " . count . " times" 


;fails -- says 7 > 8
maxindex := filebytes.maxindex()+1
if (7 > %maxindex%)
	msgbox ,  7 > 8
else
	msgbox , 7 <= 8
by pneumatic
13 Apr 2021, 04:10
Forum: Ask for Help (v1)
Topic: Efficiently read file into byte array Topic is solved
Replies: 10
Views: 1294

Re: Efficiently read file into byte array Topic is solved

Doesn't work... replace 9 with 7 and now the problem is reversed (thinks 7 > 8).
by pneumatic
13 Apr 2021, 04:06
Forum: Ask for Help (v1)
Topic: Efficiently read file into byte array Topic is solved
Replies: 10
Views: 1294

Re: Efficiently read file into byte array Topic is solved

Thanks, but that doesn't work.

However if I use parentheses and percent signs, then it works.
by pneumatic
13 Apr 2021, 02:25
Forum: Ask for Help (v1)
Topic: Efficiently read file into byte array Topic is solved
Replies: 10
Views: 1294

Re: Efficiently read file into byte array Topic is solved

SafeArray := ComObjArray(VT_UI1 := 0x11, file.Length) edit: I adapted my script to use ComObjArray's funcs, so it's all good :thumbup: Nope, AHK doing silly things internally with numbers again: filebytes := ComObjArray(VT_UI1 := 0x11, 8) ;works -- says looped 8 times loop % filebytes.maxindex()+1 ...
by pneumatic
12 Apr 2021, 23:41
Forum: Ask for Help (v1)
Topic: Efficiently read file into byte array Topic is solved
Replies: 10
Views: 1294

Re: Efficiently read file into byte array Topic is solved

Try this: file := FileOpen(myfile , "r") file.Pos := 0 SafeArray := ComObjArray(VT_UI1 := 0x11, file.Length) file.RawRead(NumGet(ComObjValue(SafeArray) + 8 + A_PtrSize), file.Length) file.Close() MsgBox, % "The first byte: " . Format("{:#x}", SafeArray[0]) ; <-- null based array Thanks, that's very...
by pneumatic
12 Apr 2021, 13:15
Forum: Ask for Help (v1)
Topic: Efficiently read file into byte array Topic is solved
Replies: 10
Views: 1294

Efficiently read file into byte array Topic is solved

Hello, I would like to read a 6MB binary file into an array of raw bytes. I am currently doing it like so, but it is very slow (around 5 minutes) and uses 467MB of RAM. file := FileOpen( myfile , "r") filebytes := [] loop { if file.RawRead(byte,1) == 1 filebytes[A_Index] := Format("{:02X}", NumGet(b...
by pneumatic
13 Jan 2020, 15:50
Forum: Ask for Help (v1)
Topic: Detect when montior is turned off or idle?
Replies: 13
Views: 6492

Re: Detect when montior is turned off or idle?

Considering this is a 4 year old thread.. Idk. But taking a look at the structure, if you're using 7 or below, GUID_MONITOR_POWER_ON is needed, which reports either 0 or 1. But, for 8+, GUID_CONSOLE_DISPLAY_STATE is used, which has 0, 1, or 2, where 2 = dimmed. How I had written it, dimmed is synon...

Go to advanced search