Jump to content

Get highlighted text, after hitting hotkey


Recommended Posts

Trying to use a clipget() along with send() (ctrl c) to copy the text, after I hit a hotkey, but it does not work...anyone have a suggestion?

 

#include <Misc.au3>
HotKeySet('!w', 'GetHighlightedWord')
While 1
    Sleep(200)
WEnd

Func GetHighlightedWord()
    Send('{LCTRL}c')
    ;_SendEx('^c') have tried this function as well
    $sWord = ClipGet()
    MsgBox(0, 'What is in the clipboard?', $sWord)


EndFunc   ;==>GetHighlightedWord

Func _SendEx($ss, $warn = "")
    Local $iT = TimerInit()
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")

        If $warn <> "" And TimerDiff($iT) > 1000 Then
            MsgBox(0, "Warning", $warn)
        EndIf
        Sleep(50)
    WEnd
    Send($ss)
EndFunc   ;==>_SendEx

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

the problem seems to be that while you are pressing  Alt-w, the GetHighlightedWord() is as well executed nearly at the same time (while your fingers are still pressing down the keyboard keys), having as final result a sum of keypresses, 2 keys pressed by You (Alt-w) and 2 keys pressed by the Send() function (Ctrl-c)
(Alt+w+Ctrl+c as result)
If you add a little delay before the Send('^c') function giving you the time to release your fingers, the function will work.....

#include <Misc.au3>
HotKeySet('!w', 'GetHighlightedWord')
While 1
    Sleep(200)
WEnd

Func GetHighlightedWord()
    Sleep(1000) ;  <-- gives you the time to release your fingers from the keyboard
    Send('^c')
    ;_SendEx('^c') have tried this function as well
    $sWord = ClipGet()
    MsgBox(0, 'What is in the clipboard?', $sWord)


EndFunc   ;==>GetHighlightedWord

Func _SendEx($ss, $warn = "")
    Local $iT = TimerInit()
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")

        If $warn <> "" And TimerDiff($iT) > 1000 Then
            MsgBox(0, "Warning", $warn)
        EndIf
        Sleep(50)
    WEnd
    Send($ss)
EndFunc   ;==>_SendEx

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

On 8/25/2016 at 2:48 PM, Chimp said:

the problem seems to be that while you are pressing  Alt-w, the GetHighlightedWord() is as well executed nearly at the same time (while your fingers are still pressing down the keyboard keys), having as final result a sum of keypresses, 2 keys pressed by You (Alt-w) and 2 keys pressed by the Send() function (Ctrl-c)
(Alt+w+Ctrl+c as result)
If you add a little delay before the Send('^c') function giving you the time to release your fingers, the function will work.....

#include <Misc.au3>
HotKeySet('!w', 'GetHighlightedWord')
While 1
    Sleep(200)
WEnd

Func GetHighlightedWord()
    Sleep(1000) ;  <-- gives you the time to release your fingers from the keyboard
    Send('^c')
    ;_SendEx('^c') have tried this function as well
    $sWord = ClipGet()
    MsgBox(0, 'What is in the clipboard?', $sWord)


EndFunc   ;==>GetHighlightedWord

Func _SendEx($ss, $warn = "")
    Local $iT = TimerInit()
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")

        If $warn <> "" And TimerDiff($iT) > 1000 Then
            MsgBox(0, "Warning", $warn)
        EndIf
        Sleep(50)
    WEnd
    Send($ss)
EndFunc   ;==>_SendEx

 

I had to add 2000 to the sleep...I will keep playing with it, to see if the number can be reduced...thanks

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Try this: highlite word or sentence and drag to the drop-window, the script:

;https://autoit.de/index.php/Thread/22579-Dropbox-f%C3%BCr-Links-aus-Browsern/?postID=185846#post185846
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


Local $hGui, $iMsg
$hGui = GUICreate("Dropbox", 150, 150, -1, -1, BitOR($WS_SIZEBOX, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUICtrlSetState(-1, $GUI_ONTOP)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 0, 0, 150, 150, -1)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_SELCHANGE)
While True
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit)
            GUIDelete()
            Exit
    EndSelect
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
    #forceref $hWnd, $iMsg, $iWparam
    Local $hWndFrom, $iCode, $tNMHDR, $tEnLink, $cpMin, $cpMax, $tMsgFilter
    $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hRichEdit
            Select
                Case $iCode = $EN_SELCHANGE
                    Checklink()
            EndSelect
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Func Checklink()
    Local $sURL, $arrValidURL
    $sURL = _GUICtrlRichEdit_GetText($hRichEdit)
    ConsoleWrite($sURL&@CRLF)
    $arrValidURL = StringRegExp($sURL, "(?s)((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)", 2)

    #comments-start
    _GUICtrlRichEdit_GetSelText($hRichEdit)
    _GUICtrlRichEdit_SetText($hRichEdit, "")
    If UBound($arrValidURL) > 0 Then
        ;// Gueltige URL ok, mach irgendwas damit
        ConsoleWrite($arrValidURL[0] & @CRLF)
        InetGet($arrValidURL[0],'test.jpg')
        ShellExecute('test.jpg')
        ;//
    EndIf
    #comments-end
EndFunc   ;==>Checklink

waiting for new drop input in the RTF-Control, you have only to change the action after line #44.

Edited by AutoBert
Link to comment
Share on other sites

21 hours ago, AutoBert said:

Try this: highlite word or sentence and drag to the drop-window, the script:

I am unable to perform this action, and I am not sure what this does, as I was able to type in the box - I assume that the consolewrite (line 44) allows me to do something?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

3 minutes ago, AutoBert said:

If you aren't able to Drag & Drop try the example to _ClipBoard_SetViewer. After start copy some text in browser or other app and have a look in the Memo Gui.

I am able to see the information in the GUI after hitting Ctrl C, but not sure how that is going to help me with what I am trying to do?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

1 minute ago, nitekram said:

I am able to see the information in the GUI after hitting Ctrl C, but not sure how that is going to help me with what I am trying to do?

Then a good starting point is to open the helpfile, reading the Language Reference. The example shows how to get ClipBoard and put data in Edit-Control.

Link to comment
Share on other sites

I am not sure I understand...I am trying to automate the population of the clipboard. By hitting one hot key, that will both start my function and copy the highlighted text. If this will do that, great, but I have never messed with these functions before, so I would need a primer to go with the examples?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

12 minutes ago, AutoBert said:

Geting highlited text is very difficult, the example i showed is not so complicated, so i don't understood why you don't know how to change for your needs.

It could be, because I am not that smart lol

The example you showed has me drag my highlighted text to a window, which I was not able to get to work...all I want is to be able to hit a hotkey, and from that function call, copy the highlighted text with sending ctrl c - coping the info to the clipboard. The delay that was mentioned before...I was able to put in a command to write to the console, and that was just enough delay to get the function working...the below code works as I want it, but I will be looking at these functions to see how I might be able to use them in the future for a clipboard keeper I have wanted to create.

 

#include <Misc.au3>
HotKeySet('^!w', 'GetHighlightedWord')
While 1
    Sleep(200)
WEnd

Func GetHighlightedWord()
    ;Sleep(2000) ;  <-- gives you the time to release your fingers from the keyboard
    ConsoleWrite('anything here for a delay')
    Send('^c')
    ;_SendEx('^c') have tried this function as well
    $sWord = ClipGet()
    MsgBox(0, 'What is in the clipboard?', $sWord)


EndFunc   ;==>GetHighlightedWord

Func _SendEx($ss, $warn = "")
    Local $iT = TimerInit()
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")

        If $warn <> "" And TimerDiff($iT) > 1000 Then
            MsgBox(0, "Warning", $warn)
        EndIf
        Sleep(50)
    WEnd
    Send($ss)
EndFunc   ;==>_SendEx

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

3 hours ago, AutoBert said:

If you aren't able to Drag & Drop try the example to _ClipBoard_SetViewer. After start copy some text in browser or other app and have a look in the Memo Gui.

If want selected text, the mentioned esample  (_ClipBoard_SetViewer) is the easiest way. Just a right click and a click on copy item and the selected text is in result of _ClipBoard_GetData(). But i prefer the Drag & Drop example, here is the selected text in the result of _GUICtrlRichEdit_GetText. I prefer this way, as it fetches only was i realy want. 

Link to comment
Share on other sites

Remember doing this at some point, script was something like...

Func GetHighlightedWord()
    ClipPut("")
    Do
        Send('^c')
        Sleep(10)
    Until ClipGet() <> ""
EndFunc

Probably had a timeout, and a test that "" actually got put in the clipboard.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

2 hours ago, JohnOne said:

Remember doing this at some point, script was something like...

Func GetHighlightedWord()
    ClipPut("")
    Do
        Send('^c')
        Sleep(10)
    Until ClipGet() <> ""
EndFunc

Probably had a timeout, and a test that "" actually got put in the clipboard.

That looks like it would work as well...thanks.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
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
 Share

×
×
  • Create New...