Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AHK Functions :: InCache() - Cache List of Recent Items


  • Please log in to reply
172 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Chr(160), which looks like a Space, which cannot name a variable.


I tried typing it directly as well as with x := Chr(160) .. Both work fine.. Thanks! :D

Regards, :)
kWo4Lk1.png

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Laszlo, :)

I would like you to change Chr(128) to Chr(160) in the following post
<!-- m -->http://www.autohotke... ... 3434#83434<!-- m -->
as in future I will be pointing it for any future request @ ask-for-help.

Regards, :)
kWo4Lk1.png

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
at your service

(but it is still your script, with a trivial mod)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

at your service


:shock:
:lol:
kWo4Lk1.png

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
This is an interesting technique. I can't comment on it much without studying it in depth because the conditions under which a variable is created dynamically are fairly complicated.

It might be of interest that you can use VarSetCapacity to retrieve the current capacity of a variable:

capacity := VarSetCapacity(x)

If the capacity is zero, the variable has either never been used or has been explicitly freed by the script (or it's a local variable that hasn't been populated yet by the function's current call).

Some variables have a permanent capacity that cannot be freed. This typically happens for those with a capacity of between 1 and 63 but that have never risen above 63. This enhances performance because the program can avoid having to ever reallocate or free such variables (which can be a costly operation when done thousands of times in a loop). It can also save memory in some cases because it uses a compressed form of memory that has less overhead than traditional dynamic memory.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Thanks for the important and useful information. :)

VarExist() had relevance to the post @ Ask-for-help topic: How to determine if variable exists? by Richard where

"Is there a way in autohotkey to determine whether a certain variable exists?"

"I would like to be able to tell the difference between a variable that does not exist and a variable that exists, but has an empty-string for a value."


I am not able to guess where this would be very useful, or how many people would really need it, but is it possible to have in-built function like VarExist() to test Variables ?

Regards, :)
kWo4Lk1.png

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

is it possible to have in-built function like VarExist() to test Variables ?

Would be useful with #MustDeclareVars.
Since there's IsLabel() already I would prefer to have IsVar().

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Since there's IsLabel() already I would prefer to have IsVar().


I wanted the function to sound like WinExist().
This is because the function would return the pointer if the variable existed. Since A_??* variables did not have a pointer I chose to return 0,1,2 instead.

IsVar() sounds good!

:)
kWo4Lk1.png

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

I wanted the function to sound like WinExist().

Me too, one would expect IsLabel(LabelName, Type). In the end, it's Chris' decision.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

SoundCard()

Returns the number of soundcards available on a system.
A script can test the target machine for availability of a soundcard before playing an audio file.

SoundCard() {
Return DllCall("winmm.dll\waveOutGetNumDevs")
}

Example:
If SoundCard() 
   SoundPlay, %A_WinDir%\Media\The Microsoft Sound.wav, wait
Return

SoundCard() {
Return DllCall("winmm.dll\waveOutGetNumDevs")
}

I am surprised to find search does not reveal any requests for this :roll:
Anyways!, :D


PS: For midi one may use DllCall("winmm.dll\midiOutGetNumDevs") to ascertain midi compatibility!
kWo4Lk1.png

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

AviFileInfo()

Returns the video properties of an AVI file as a pipe delimited string.

MSDN Reference:

AVIFILEINFO Structure : <!-- m -->http://msdn2.microso...y/ms706413.aspx<!-- m -->

AVIFileInit : <!-- m -->http://msdn2.microso...y/ms706415.aspx<!-- m -->
AVIFileOpen : <!-- m -->http://msdn2.microso...y/ms706420.aspx<!-- m -->
AVIFileInfo : <!-- m -->http://msdn2.microso...y/ms706309.aspx<!-- m -->
AVIFileRelease : <!-- m -->http://msdn2.microso...y/ms706528.aspx<!-- m -->
Here is the function along with a working example:


; Written by A.N.Suresh Kumar AKA "Goyyah", 23-Nov-2006
; Post: http://www.autohotkey.com/forum/viewtopic.php?p=91036#91036

Loop, %A_WinDir%\*.AVI {

AviFileInfo := AviFileInfo(A_LoopFileLongPath)
StringSplit, Field, AviFileInfo, |

FPS      := (Field8/Field7) ;  FPS is dwRate / dwScale 
Duration := FormatSeconds(Round(Field9/FPS,0)) ; Duration is dwLength / FPS

MsgBox, 0, Properties :: %A_LoopFileName%,
(
FileFullPath     `t: %A_LoopFileLongPath%
FileSize         `t: %A_LoopFileSizeKB% KB

MaxBytesPerSec   `t: %Field1%
Flags            `t: %Field2%
Caps             `t: %Field3%
No Of Streams    `t: %Field4%
Sugg. BufferSize `t: %Field5%
Video Size       `t: %Field6%
[color=red]Frames per second`t: %FPS%
Duration         `t: %Duration%[/color]
Scale            `t: %Field7%
Rate             `t: %Field8%
Frames           `t: %Field9%
Edit Count       `t: %Field10%
File Type        `t: %Field11%
)
}
Return

[color=blue]AviFileInfo(AviFile)[/color] {
VarSetCapacity( av, 108, 0 )                           ; av = AVIFILEINFO structure
DllCall( "avifil32.dll\AVIFileInit" )
DllCall( "avifil32.dll\AVIFileOpenA", Intp,hFile, Str,AVIFile , Int,0, Int,0 )
DllCall( "avifil32.dll\AVIFileInfoA", Int,hFile, Int,&av, Int,108 )
DllCall( "avifil32.dll\AVIFileRelease", Int,hFile )
mb := (*(&av+ [color=red]0[/color]))+(*(&av+ [color=red]1[/color])<<8)+(*(&av+ [color=red]2[/color])<<16)+(*(&av+ [color=red]3[/color])<<24) ; dwMaxBytesPerSec
fl := (*(&av+ [color=red]4[/color]))+(*(&av+ [color=red]5[/color])<<8)+(*(&av+ [color=red]6[/color])<<16)+(*(&av+ [color=red]7[/color])<<24) ; dwFlags
ca := (*(&av+ [color=red]8[/color]))+(*(&av+ [color=red]9[/color])<<8)+(*(&av+[color=red]10[/color])<<16)+(*(&av+[color=red]11[/color])<<24) ; dwCaps
st := (*(&av+[color=red]12[/color]))+(*(&av+[color=red]13[/color])<<8)+(*(&av+[color=red]14[/color])<<16)+(*(&av+[color=red]15[/color])<<24) ; dwStreams
sb := (*(&av+[color=red]16[/color]))+(*(&av+[color=red]17[/color])<<8)+(*(&av+[color=red]18[/color])<<16)+(*(&av+[color=red]19[/color])<<24) ; dwSuggBufferSize
wi := (*(&av+[color=red]20[/color]))+(*(&av+[color=red]21[/color])<<8)+(*(&av+[color=red]22[/color])<<16)+(*(&av+[color=red]23[/color])<<24) ; dwWidth
he := (*(&av+[color=red]24[/color]))+(*(&av+[color=red]25[/color])<<8)+(*(&av+[color=red]26[/color])<<16)+(*(&av+[color=red]27[/color])<<24) ; dwHeight
sc := (*(&av+[color=red]28[/color]))+(*(&av+[color=red]29[/color])<<8)+(*(&av+[color=red]30[/color])<<16)+(*(&av+[color=red]31[/color])<<24) ; dwScale
ra := (*(&av+[color=red]32[/color]))+(*(&av+[color=red]33[/color])<<8)+(*(&av+[color=red]34[/color])<<16)+(*(&av+[color=red]35[/color])<<24) ; dwRate
le := (*(&av+[color=red]36[/color]))+(*(&av+[color=red]37[/color])<<8)+(*(&av+[color=red]38[/color])<<16)+(*(&av+[color=red]39[/color])<<24) ; dwLength
ec := (*(&av+[color=red]40[/color]))+(*(&av+[color=red]41[/color])<<8)+(*(&av+[color=red]42[/color])<<16)+(*(&av+[color=red]43[/color])<<24) ; dwEditCount
Loop, 64                                                         
         ft := ft . Chr( *(&av+[color=red]43[/color]+(A_Index)) )                   ; szFileType[64]
Return mb "|" fl "|" ca "|" st "|" sb "|" wi "x" he "|" sc "|" ra "|" le "|" ec "|" ft
}

[color=blue]FormatSeconds(NumberOfSeconds)[/color]  { ; Taken from AHK Documentation ( FormatTime )
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    return NumberOfSeconds//3600 ":" mmss  
}

Snapshots of the message boxes:
Posted Image______Posted Image
Edit Note: Do not be discouraged by the bit-shifting seen inside the AviFileInfo() function. It is actually easy to modify. You can keep what you want and delete the rest like the example follows:

AviFileInfo(AviFile) { 
VarSetCapacity( av, 108, 0 )                           ; av = AVIFILEINFO structure 
DllCall( "avifil32.dll\AVIFileInit" ) 
DllCall( "avifil32.dll\AVIFileOpenA", Intp,hFile, Str,AVIFile , Int,0, Int,0 ) 
DllCall( "avifil32.dll\AVIFileInfoA", Int,hFile, Int,&av, Int,108 ) 
DllCall( "avifil32.dll\AVIFileRelease", Int,hFile ) 
wi := (*(&av+20))+(*(&av+21)<<8)+(*(&av+22)<<16)+(*(&av+23)<<24) ; dwWidth 
he := (*(&av+24))+(*(&av+25)<<8)+(*(&av+26)<<16)+(*(&av+27)<<24) ; dwHeight 
Return wi "x" he ; only the video size
}

:)


kWo4Lk1.png

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Very nice.
I don't see why you didn't wrapped up the field reading in some function (I would have used my GetNextUInt function to even avoid any offset computing), as all these numbers are hard to read and maintain.
Anyway, you uncovered some interesting functions, thanks.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear PhiLho, :)

Very nice.


Thanks! :D

I don't see why you didn't wrapped up the field reading in some function (I would have used my GetNextUInt function to even avoid any offset computing), as all these numbers are hard to read and maintain.


Originally I had used ExtractInteger(), then absorbed it within the function to make it standalone.
I am waiting for ExtractInteger() & InsertInteger() to be built into AHK. :)
I have been playing with pointers a lot these days, and the best is yet to come.

Yes .. It is hard to read .. I will try to do some colouring!

Thanks again & Regards, :)
kWo4Lk1.png

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

DriveSpace()

Returns the FreeSpace / Capacity of a Drive in bytes.
Parameter 1 should be a valid drive letter.
Parameter 2 should be 1 for fetching the freespace and 2 for retrieving the drive capacity.


FreeSpace     := DriveSpace("C:\", 1) 
DiskCapacity  := DriveSpace("C:\", 2)
MsgBox, 64,Drive C:, % "FreeSpace`t: " FreeSpace "`nDrive Capacity`t: " DiskCapacity
Return 

DriveSpace(Drv="", Free=1) { 
DriveGet, Drives, List 
StringLeft, Drv, Drv, 1 
If (!InStr(Drives,%Drv%)) 
    Return -1 
Drv := Drv . ":\" 
VarSetCapacity(SPC, 30, 0)  ; Sectors Per Cluster 
VarSetCapacity(BPS, 30, 0)  ; Bytes Per Sector 
VarSetCapacity(FC , 30, 0)  ; Free Clusters 
VarSetCapacity(TC , 30, 0)  ; Total Clusters 
DllCall("GetDiskFreeSpaceA", Str,Drv, UIntp,SPC 
                , UIntp,BPS, UIntp,FC, UIntp,TC) 
Return Free=1 ? (SPC*BPS*FC) : (SPC*BPS*TC) ; Ternary Operator requires 1.0.46+
}

Requested at Ask For Help Topic : Hard Disk Drive
Thanks to PhiLho. DriveSpaceFreeBytes() was changed to DriveSpace() and now it also retrieves a drive's capacity.


** Edit: Function Optimised/Shortened on 04-Nov-2009 **

DriveSpace( D="C:", M=1) {
If DllCall( "GetDiskFreeSpaceA", Str,Chr(*(&D)) ":", UIntP,S, UIntP,B, UIntP,F, UIntP,T )
   Return M ? (S*B*F) : (S*B*T)
}

FormatByteSize( I=0 ) {
 VarSetCapacity(F,16), DllCall( "shlwapi.dll\StrFormatByteSize64A", Int64,I,Str,F,Int,16 )
Return F
}


PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Useful function.
To get total space of disk, use Return SPC * BPS * TC instead of Return SPC * BPS * FC...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")