Jump to content

Can I use function's parameter in HotKeySet?


Recommended Posts

I usually just set my Parms as default. You could always call it from a funtion.

$msg = "trying..."
HotKeySet("#!c", "MyFunc")


Func MyFunc()
MsgBox(4096, "", $msg)
EndFunc

$msg = "trying..."
HotKeySet("#!c", "Parm")

func Parm()
MyFunc($msg)
endfunc

Func MyFunc($msg)
MsgBox(4096, "", $msg)
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to post
Share on other sites

I usually just set my Parms as default. You could always call it from a funtion.

$msg = "trying..."
HotKeySet("#!c", "MyFunc")
Func MyFunc()
MsgBox(4096, "", $msg)
EndFunc

$msg = "trying..."
HotKeySet("#!c", "Parm")

func Parm()
MyFunc($msg)
endfunc

Func MyFunc($msg)
MsgBox(4096, "", $msg)
EndFunc

<{POST_SNAPBACK}>

Sorry, I dont' want to do that....I want to do this:

1. I detect how many CD-ROM in the computer.

2. Then I'll create a hotkey (like WIN+ALT+1, etc)...so If the computer have 2 CD-ROMs (Like I have ;) ), I'll create two hotkey (WIN+ALT+1 and WIN+ALT+2) to eject the CD-ROM.

3. So, If the computer have 8 CD-ROMs, I don't want to create too many function for the hotkeys....In my opinion, the easiest way is using function's parameter....but AutoIt can't do that... :):)

Link to post
Share on other sites

Say you wanted to see how many CDRoms, and have the function use some other source of info?

My point is, I could put the function in the hotkey, or it could be dynamic as well. I will grant you there is 3 more lines of code however.

HotKeySet("#!c", "Parm")

$x=StringSplit("Almost,Hello there, Hiya fred, bob likes juice, sam has 3 CD roms",",")

$var = DriveGetDrive( "CDROM" )

While 1
for $i=1 to $x[0]
$msg = $x[$i]
next
wend

func Parm()
MyFunc($msg)
endfunc

Func MyFunc($msg)
MsgBox(4096, $var[0]& "CDROMS", $msg)
EndFunc

func Parm()
MyFunc($msg)
endfunc
HotKeySet("#!c", "Parm")

is the same as

HotKeySet("#!c", "MyFunc($msg)")
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to post
Share on other sites

No...not like that...sorry I can't explained it in detail, because my english is not good..:D this is the sample code and I hope you understand :)

; ----------------------------------------------------------------------------
; Set Hotkey for All CD-ROM (WIN+ALT+1 for First CD-ROM...)
; ----------------------------------------------------------------------------
  $var = DriveGetDrive( "CDROM" )
  If NOT @error Then
     For $i = 1 to $var[0]
         $setting = "#!" & $i
         $DriveLetter = $var[$i]
         HotKeySet($setting, "OpenCDROM($DriveLetter)")
     Next
  EndIf
; ----------------------------------------------------------------------------

Func OpenCDROM($Drive)
     MsgBox(64, "Try", $Drive)
EndFunc

so, If I have 10 CD-Roms or 100 CD-Roms, I don't care...the code above can handle it (if AutoIt support function parameter in HotKeySet)... :);)

Now, is it clear? :(:idiot:

Link to post
Share on other sites

YESSSSS...you are right :);):D:(

Sorry, I am replying when you reply :)

Actually, I think he wants to do something like this.

$Drives = DriveGetDrive('CDROM');

For $i = 1 to $Drives[0]
  HotKeySet('#!' & $i, EjectDrive($Drives[$i]));
Next

Func EjectDrive($DriveLet)
  CDTray($DriveLet);
EndFunc

<{POST_SNAPBACK}>

Link to post
Share on other sites

Ok, now I remember trying to do something just like this in the past. It will take a bit more thought now. My first thought is to use Larry's trick.

Set a hotkeylogger for a sequence of keys. Much like his "Larry" thing. You could have it read the first two keys, and use the third key to be the letter of the drive to open.

Dynamically making hotkeys is something I forgot about. Thanks, it is really refreshing.

I wish I could dynamically create functions.

for $i= 1 to 10; not going to work.
Func $i()
send($i)
endfunc
next

Well maybe in the morning I might have some insight, but you are right, I couldn't see the forest for the trees that time... :)

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...