 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Fri Oct 13, 2006 5:28 pm Post subject: |
|
|
| Laszlo wrote: | | 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!
Regards,  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Fri Oct 13, 2006 7:39 pm Post subject: |
|
|
Dear Laszlo,
I would like you to change Chr(128) to Chr(160) in the following post
http://www.autohotkey.com/forum/viewtopic.php?p=83434#83434
as in future I will be pointing it for any future request @ ask-for-help.
Regards,  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Fri Oct 13, 2006 7:46 pm Post subject: |
|
|
at your service
(but it is still your script, with a trivial mod) |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Fri Oct 13, 2006 7:47 pm Post subject: |
|
|
| Laszlo wrote: | | at your service |
 _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sun Oct 15, 2006 1:23 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Sun Oct 15, 2006 10:24 am Post subject: |
|
|
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
| Richard as guest wrote: | "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,  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Sun Oct 15, 2006 10:58 am Post subject: |
|
|
| Goyyah wrote: | | 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(). _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Sun Oct 15, 2006 11:32 am Post subject: |
|
|
| Titan wrote: | | 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!
 _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Sun Oct 15, 2006 12:42 pm Post subject: |
|
|
| Goyyah wrote: | | I wanted the function to sound like WinExist(). | Me too, one would expect IsLabel(LabelName, Type). In the end, it's Chris' decision. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Fri Nov 10, 2006 9:37 pm Post subject: SoundCard() |
|
|
| Quote: | 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.
| Code: | SoundCard() {
Return DllCall("winmm.dll\waveOutGetNumDevs")
} |
Example:
| Code: | 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
Anyways!,
|
PS: For midi one may use DllCall("winmm.dll\midiOutGetNumDevs") to ascertain midi compatibility! _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Thu Nov 23, 2006 3:15 pm Post subject: AviFileInfo() |
|
|
| Quote: | AviFileInfo()
Returns the video properties of an AVI file as a pipe delimited string.
Here is the function along with a working example:
| Code: | ; 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%
Frames per second`t: %FPS%
Duration `t: %Duration%
Scale `t: %Field7%
Rate `t: %Field8%
Frames `t: %Field9%
Edit Count `t: %Field10%
File Type `t: %Field11%
)
}
Return
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 )
mb := (*(&av+ 0))+(*(&av+ 1)<<8)+(*(&av+ 2)<<16)+(*(&av+ 3)<<24) ; dwMaxBytesPerSec
fl := (*(&av+ 4))+(*(&av+ 5)<<8)+(*(&av+ 6)<<16)+(*(&av+ 7)<<24) ; dwFlags
ca := (*(&av+ 8))+(*(&av+ 9)<<8)+(*(&av+10)<<16)+(*(&av+11)<<24) ; dwCaps
st := (*(&av+12))+(*(&av+13)<<8)+(*(&av+14)<<16)+(*(&av+15)<<24) ; dwStreams
sb := (*(&av+16))+(*(&av+17)<<8)+(*(&av+18)<<16)+(*(&av+19)<<24) ; dwSuggBufferSize
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
sc := (*(&av+28))+(*(&av+29)<<8)+(*(&av+30)<<16)+(*(&av+31)<<24) ; dwScale
ra := (*(&av+32))+(*(&av+33)<<8)+(*(&av+34)<<16)+(*(&av+35)<<24) ; dwRate
le := (*(&av+36))+(*(&av+37)<<8)+(*(&av+38)<<16)+(*(&av+39)<<24) ; dwLength
ec := (*(&av+40))+(*(&av+41)<<8)+(*(&av+42)<<16)+(*(&av+43)<<24) ; dwEditCount
Loop, 64
ft := ft . Chr( *(&av+43+(A_Index)) ) ; szFileType[64]
Return mb "|" fl "|" ca "|" st "|" sb "|" wi "x" he "|" sc "|" ra "|" le "|" ec "|" ft
}
FormatSeconds(NumberOfSeconds) { ; 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:
______
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:
| Code: | 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
} |
|
_________________ SKAN - Suresh Kumar A N
Last edited by SKAN on Fri Dec 01, 2006 11:57 pm; edited 2 times in total |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu Nov 23, 2006 3:43 pm Post subject: |
|
|
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. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Thu Nov 23, 2006 4:25 pm Post subject: |
|
|
Dear PhiLho,
Thanks!
| You wrote: | | 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,  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Fri Dec 01, 2006 7:46 pm Post subject: DriveSpaceFreeBytes() |
|
|
| Quote: | 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.
| Code: | 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.
|
Regards,  _________________ SKAN - Suresh Kumar A N
Last edited by SKAN on Mon Dec 04, 2006 6:53 pm; edited 1 time in total |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Mon Dec 04, 2006 6:26 pm Post subject: |
|
|
Useful function.
To get total space of disk, use Return SPC * BPS * TC instead of Return SPC * BPS * FC... _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|