Jump to content

Reliably way to get/copy selected text


Sunaj
 Share

Recommended Posts

Ok, I've made a small script to manipulate text it gets the selected text in a given word/txt file by me pressing a hotkey, the important bit goes like this:

......
Send("^c")
ClipPut(StringLower (ClipGet()))
Send("^v")
......

The problem is that the Send("^c") way of getting the text does not come through as 100% reliable - often when the script is run for the first time it will fail simply by Send("^v")'ing the last copied item instead of the one currently selected. Any ideas for replacing the Send("^c") method of getting the text plus ideas for error correction would be highly appreciated.

Link to comment
Share on other sites

Try slowing things down a wee bit by using some sleep commands, see if it makes a difference

HotKeySet("{F6}", "CopyText")
HotKeySet("{F7}", "PasteText")

While 1
    Sleep(10)
WEnd

Func CopyText()
    Send("{CTRLDOWN}")
    Sleep(100)
    Send("c")
    Sleep(100)
    Send("{CTRLUP}")
EndFunc

Func PasteText()
    Send("{CTRLDOWN}")
    Sleep(100)
    Send("v")
    Sleep(100)
    Send("{CTRLUP}")
EndFunc
Link to comment
Share on other sites

Try slowing things down a wee bit by using some sleep commands, see if it makes a difference

Thanks for quick reply, it DOES make a difference, however, the thing is I would much prefer a more 'cleancut' approach to the problem (i.e. solving it with a system/dll call of some sort or another) since the sleep command way of 'fixing' it is more of a workaround - if the system is under stress or the script is used on a slower computer it is likely to fail.

btw: it does seem to do a difference simply to use the Send("{CTRLDOWN}")/Send("{CTRLUP}") without all the sleeps - i'll report back if the fix is stable :lmao:

Edited by Sunaj
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...