Sign in to follow this  
Followers 0
mistabirdy

HotKey with Marked Text as Arguments

7 posts in this topic

Hello Community,

I like to mark a text and press a hotkey than one programm/script should be called and give this programm/script the marked text as argument to do something.

How can I realise this?

Creating Hotkey is not a problem. I can even create a normal windows shortcut and assign a hotkey.

The question is, how to pass the marked text as an argument.

Share this post


Link to post
Share on other sites



Where do you mark the text? In a GUI you created with the AutoIt script, in an Office application (word, excel ...), in a browser ..?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It can be anywhere. Word, Excel, Web Browser, Texteditor, AutoIt GUI ...

Share this post


Link to post
Share on other sites

What I would do (probably not the best way to do it tho) would be like this:

HotKeySet("^q", "_HotkeyPressed") ;The hotkey is CTRL+Q and the function name is "_HotkeyPressed"
While 1 ;Just an infinite loop until the program exits
WEnd
Func _HotkeyPressed()
    $PreviousClipboard = ClipGet();Used to prevent data loss when running the function
    Send("^c")
    $Argument = ClipGet()
    Switch $Argument ;We are using a switch here because the variable we compare to will always be the same
        Case "Argument1" ;If the selected text was argument 1
            MsgBox(0,"",'Selected text was "Argument1"')
        Case "Argument2" ;If the selected text was argument 2
            MsgBox(0,"",'Selected text was "Argument2"')
        Case "Exit"
            MsgBox(0,"","The program will now exit")
            Exit
        Case Else ;If the selected text was not covered by any of the previous case expressions
            MsgBox(0,"",'Selected text was "' & $Argument & '"')
    EndSwitch
    ClipPut($PreviousClipboard);Ensures that the user doesnt lose any data on their clipboard
    Return
EndFunc

I haven't tested this but there isn't a doubt in my mind as to whether it will work or not.

Share this post


Link to post
Share on other sites

Thank you very much Mikeman!! It's working

It's working ... maybe It could have problem if there is a object/image copied in the clip. But I don't care about this :)

Share this post


Link to post
Share on other sites

Yeah, that's true. I might be able to think of a way that it might be able to get image URLs, but what sort of objects are you referring to?

Share this post


Link to post
Share on other sites

You should put some Sleep in the While...WEnd loop, at least 10.., to avoid CPU bashing.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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