Jump to content

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

Online Function Library


  • Please log in to reply
13 replies to this topic
Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
Use this thread as an Online Function Library. Everyone is allowed to post their functions for general use. Just like Jon's attempt to catalogue all most useful scripts at one place, this is mine for the functions. The difference is that you can yourself add your own functions here. You can link to the forum post relating to your function, or directly to the script file hosted anywhere. The next post is editable by anyone. Just login using the credentials given below and add your functions there.
ahkuser:ahkuser

It'd be nice for users if u categorize your functions.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


ahkuser
  • Members
  • 9 posts
  • Last active: Jun 18 2007 05:17 PM
  • Joined: 27 May 2005
Post Functions here.

ControlGetHWND
=====================
DecToHex(In_Val) here
RGBtoHex(R,G,B) here
GetRelPos(In_X,In_Y,In_Angle,In_Radius,Byref Tx, Byref Ty) here
LeapYear(In_Year) here
StringDelete(In_String,In_Start,In_Count) here
StringFlip(In_String) here
StringGetChar(In_String,In_Posi,Param3) here
StringInsert(In_String,In_Posi,In_Insert) here
StringReplaceChar(ByRef In_String,In_Posi,New_Char) here
Swap_Values(Byref val1, ByRef Val2) here
DegToRad(In_Deg) here
RadToDeg(In_Rad) here
=====================
Pixel Matrix Search here

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

Simple function, returns path of default browser so you can open links in new windows (with the system's default browser ofcourse).
; The next line is an example (function below)
Run, % Web() "http://www.google.com/ig"

Web()
{
	RegRead, htmlOpenPath, HKCR, htmlfile\shell\open\command
	Return, %htmlOpenPath%
}
--------------------------------------------------

I posted this somewhere else but for anybody who needs it...
This makes vars you might've got from FileRead/RegRead/IniRead that have escaped variables into real variables, see the example in the script.

Download

--------------------------------------------------

Commands Function Collection - functionized all comands that have an outputvar :)

--------------------------------------------------

WinFX! - Some gui window effects/animations.
Download Functions
Download Example

--------------------------------------------------

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
i needed that sometime ago! by the way i think u should also link your cmd functions topic in this thread.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
I put up a winfx function script.

Should I bump this topic everytime I post a new function :?:

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
It probably depends on how often you add them. If it's only once a week, a bump is probably justified. If more often, perhaps you could update the post every time but only bump once a week.

Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
Very nice collection - I'll try to add it to the Functions page of the AHK wiki over the weekend.

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Returns the Factorial of a number-

Factorial(number)
{
  sum=%number%
    loop
    {
      if ((number-a_index) <= 1)
        break
      sum:=sum*(number-a_index)
    }
  return sum
}


Converts Hexadecimal to Decimal-

(positive and negative is not taken into account as I wrote it for colour conversion.)

HEXtoDEC(HEX)
{
  StringUpper, HEX, HEX
  loop, % StrLen(HEX)
  {
    StringMid, Col, HEX, % (StrLen(HEX)+1)-a_index, 1
    if Col is integer
      DEC1:=Col*16**(a_index-1)
    Else
      DEC1:=(Asc(Col)-55)*16**(a_index-1)
  DEC+=%DEC1%
  }
  return DEC
}


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

Converts Hexadecimal to Decimal-

To convert an integer from decimal to hexadecimal, use this example (the converse can be used to convert in the opposite direction):

SetFormat, integer, hex
VariableContainingAnInteger += 0
SetFormat, integer, d


autohotkey.com/net Site Manager

 

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


Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
I didn't notice that :oops:

I wondered why I couldn't find an existing function to do it :)

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
:?:
Hex2Dec(_hex)
{
	local intFormat, dec
	intFormat = %A_FormatInteger%
	SetFormat Integer, D
	dec += "0x" . _hex
	SetFormat Integer, %intFormat%
	Return dec
}
The function may be used if you are not sure if the SetFormat was set to hex before calling the function... Actually, no need for function if you never set it:
d := 0
d += "0x" . hexDigits

The topic is old, but I believe such useful list should go to the Wiki, easier to maintain than a list of messages.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Strictly speaking, the Factorial function is not correct, because it returns 0 for 0!, but the right value is 1. Here it is corrected:
MsgBox % "0!="Factorial(0)", 1!="Factorial(1)", 2!="Factorial(2)", 5!="Factorial(5)
Factorial(n) {
   f = 1
   loop %n%
      f *= A_Index
  return f 
}
As PhiLho said, if your current integer format is decimal (the default), you don't need a function to convert a hex number to decimal form. Just add 0 to the hex number and AHK converts it to decimal:
hex = 0xFF
dec := hex+0 ; dec = hex converted to decimal
MsgBox % hex+0 ; can be used in output w/o assigning to vars


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

local intFormat, dec

I'm curious as to why you define the local variables when there is no need to:

Functions[/url]":3kqwhcnk]All variables referenced or created inside a function are local by default (except built-in variables such as Clipboard, ErrorLevel, and A_TimeIdle).

The function may be used if you are not sure if the SetFormat was set to hex before calling the function...

You can use A_FormatInteger and A_FormatFloat.

autohotkey.com/net Site Manager

 

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


Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004

dec := hex+0 ; dec = hex converted to decimal


I didn't expect it to be that simple :shock:

Strictly speaking, the Factorial function is not correct, because it returns 0 for 0!, but the right value is 1. Here it is corrected:


I didn't notice that. Thanks for the amended version.

I was actually using that function for a Permutation script that I was writing yesterday (just to see if I could write one). After a couple hours of writing it, I found one you had written already that worked a hundred times faster :oops:


Thanks for your comments and corrections.