Sign in to follow this  
Followers 0
giovanigonzales

HotKeySet function parameters

7 posts in this topic

HotKeySet ( "key" [, "function"] )

No way I can send a parameter to the function?

I am setting a dozen of hotkeys, and all I need is to call the same function with diferent parameters

so at this moment my script, looks dumb, like this:

HotKeySet("^!u", "Func1")

HotKeySet("^!o", "Func2")

HotKeySet("^!i", "Func3")

...

While 1

Sleep(100)

WEnd

Func SendUnicode($text)

$SaveClip = ClipGet()

ClipPut($text)

Send("^v")

ClipPut($SaveClip)

EndFunc

Func Func1()

SendUnicode("ü")

EndFunc

Func Func2()

SendUnicode("ö")

EndFunc

Func Func3()

SendUnicode("ï")

EndFunc

...

would be much better to define keys this way:

HotKeySet("^!u", "SendUnicode(1)")

HotKeySet("^!u", "SendUnicode(2)")

HotKeySet("^!u", "SendUnicode(3)")

....

and then In the SendUnicode function i will implement a "case" to send the desired text depending on the code. That would erase the dumb copy-paste functions Func1, Func2, Func3 ... etc

Share this post


Link to post
Share on other sites



No. You can't and you don't need to. Just set them all to the same function and use the @HotKeyPressed macro to determine your actions:

HotKeySet("^!u", "HotKeyFunc")
HotKeySet("^!o", "HotKeyFunc")
HotKeySet("^!i", "HotKeyFunc")
HotKeySet("{ESC}", "_Quit")

While 1
    Sleep(100)
WEnd

Func HotKeyFunc()
    Switch @HotKeyPressed
        Case "^!u"
            SendUnicode("ü")
        Case "^!o"
            SendUnicode("ö")
        Case "^!i"
            SendUnicode("ï")
    EndSwitch
EndFunc   ;==>HotKeyFunc

Func SendUnicode($text)
    ConsoleWrite("Debug: " & $text & @LF)
EndFunc   ;==>SendUnicode

Func _Quit()
    Exit
EndFunc

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You can do this in one function...

HotKeySet("^!u", "Func1")
HotKeySet("^!o", "Func1")
HotKeySet("^!i", "Func1")

While 1
    Sleep(100)
WEnd

Func Func1()
    Local $Unicode_Txt = ""
    
    Switch @HotKeyPressed
        Case "^!u"
            $Unicode_Txt = "u"
        Case "^!o"
            $Unicode_Txt = "o"
        Case "^!i"
            $Unicode_Txt = "i"
    EndSwitch
    
    SendUnicode($Unicode_Txt)
EndFunc

Func SendUnicode($text)
    $SaveClip = ClipGet()
    ClipPut($text)
    Send("^v")
    ClipPut($SaveClip)
EndFunc

But yes, passing parameters to HotkeySet function will be usefull addition :) - I think it will be implemented some day, check this thread.


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

HotKeySet ( "key" [, "function"] )

No way I can send a parameter to the function?

I am setting a dozen of hotkeys, and all I need is to call the same function with diferent parameters

so at this moment my script, looks dumb, like this:

HotKeySet("^!u", "Func1")

HotKeySet("^!o", "Func2")

HotKeySet("^!i", "Func3")

...

While 1

Sleep(100)

WEnd

Func SendUnicode($text)

$SaveClip = ClipGet()

ClipPut($text)

Send("^v")

ClipPut($SaveClip)

EndFunc

Func Func1()

SendUnicode("ü")

EndFunc

Func Func2()

SendUnicode("ö")

EndFunc

Func Func3()

SendUnicode("ï")

EndFunc

...

would be much better to define keys this way:

HotKeySet("^!u", "SendUnicode(1)")

HotKeySet("^!u", "SendUnicode(2)")

HotKeySet("^!u", "SendUnicode(3)")

....

and then In the SendUnicode function i will implement a "case" to send the desired text depending on the code. That would erase the dumb copy-paste functions Func1, Func2, Func3 ... etc

If you are going to have a function SendUnicode with a Case then you can eliminate the Func1, Func2 etc

HotKeySet("^!u", "SendUnicode")
HotKeySet("^!o", "SendUnicode")
HotKeySet("^!i", "SendUnicode")

While 1
Sleep(100)
WEnd

Func SendUnicode()
$SaveClip = ClipGet()

switch @HotKeyPressed
  Case "^!u"
      ClipPut("1")
  Case "^!o"
     ClipPut("2")
  Case "^!i"
     ClipPut("3")
EndSwitch

Send("^v")
ClipPut($SaveClip)
EndFunc

EDIT: I was a bit slow.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

PsaltyDS

Our codes are very similar :), but i didn't seen yours when i posted :) ...

I think we need an option here on forum, so that when someone has repplied before you, it will jump for you to Full Edit mode and alert you about that (that someone has already repplied to the topic, and you might want to see what he repplied).


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

damn! I should have read the help carefully!

"@HotKeyPressed macro can be used inside the function to handle several keys in the same function."

Thanks to all for response, you are all very kind

Share this post


Link to post
Share on other sites

PsaltyDS

Our codes are very similar :), but i didn't seen yours when i posted :) ...

Great minds think alike...

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


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
Sign in to follow this  
Followers 0