Sign in to follow this  
Followers 0
tauruzian

How to perform shorcut key (Ctrl C + Crtl V)

11 posts in this topic

Hi,

How do I perform short cut key in Auto It. For an example I need to copy a text from text file. How do I perform 'Ctrl C' and 'Ctrl V' using Auto It. Any suggestion or reference links is highly appreciated. Thanks.

Share this post


Link to post
Share on other sites



Is there a reason you need to use a shortcut key rather than using the built in FileRead or FileReadLine functions?

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I need to read certain text for the entire document. For an example, if user just highlight(using mouse and highlight the text) the first paragraph of the entire document, I just need to read those. I cannot predefine which line to be read since the user might select any text in the document.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The easiest way to do this is to read the help file. You may want to use the Send() or ControlCommand() or maybe even the ClipPut() function.

Edited by somdcomputerguy

- 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

The easiest way to do this is to read the help file. You may want to use the Send() or ControlCommand() or maybe even the ClipPut() function.

Func addToClipboard()
Send ("^c")
sleep(1000) ;
EndFunc
and
Func printOutput2()
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("^v")
EndFunc
does the trick, but how do I refer to particular document. For an example get ctrl c for test.txt. Please advice. 

Share this post


Link to post
Share on other sites

Run("notepad.exe test.txt")

or

ShellExecute("notepad.exe", "test.txt")

or

ShellExecute("test.txt")

if files with .txt extension are associated with notepad.


- 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
Run("notepad.exe test.txt")

or

ShellExecute("notepad.exe", "test.txt")

or

ShellExecute("test.txt")

if files with .txt extension are associated with notepad.

The notepad is active. For an example, I open the test.txt, highlight some text in the txt file, run the auto it script. How do I point the script to the active document.

Share this post


Link to post
Share on other sites

How do I point the script to the active document.

o:) o:)

Post your script code. Use the AutoIt code tags! :thumbsup:


- 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

You don't need to point the script to the active window. Send commands only interact with the active window. If the window loses focus you can use WinActivate().

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

WinGetHandle for notepad window

ControlGetHandle for notepad edit area

_GUICtrlEdit_GetSel to get the selected character positions

StringMid to retrieve data

Modified helpfiles "example" for a quick example of use:

**Edit**:  Please don't think to just use this out of the box without error checking, this is just an example!

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hStatusBar, $idEdit, $hGUI
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"
    Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\include\_ReadMe_.txt"
    Local $aPartRightSide[3] = [190, 378, -1], $aSel

    ; Create GUI
    $hGUI = GUICreate("Edit Get Sel", 400, 300)
    $idEdit = GUICtrlCreateEdit("", 2, 2, 394, 268, BitOR($ES_WANTRETURN, $WS_VSCROLL))
    $hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aPartRightSide)
    _GUICtrlStatusBar_SetIcon($hStatusBar, 2, 97, "shell32.dll")
    GUISetState(@SW_SHOW)

    ; Set Margins
    _GUICtrlEdit_SetMargins($idEdit, BitOR($EC_LEFTMARGIN, $EC_RIGHTMARGIN), 10, 10)

    ; Set Text
    _GUICtrlEdit_SetText($idEdit, FileRead($sFile))

    ; Set Sel
    _GUICtrlEdit_SetSel($idEdit, 15, 20)

    ; Get Sel
    $aSel = _GUICtrlEdit_GetSel($idEdit)
    
    Local $sz_selected = StringMid(ControlGetText($hGUI, "", $idEdit), $aSel[0], ($aSel[1] - $aSel[0]) + 1)
    MsgBox(64, "Selected Text", $sz_selected)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Hello

If you want to use ctrl-c/v i use: Send("{CTRLDOWN}v{CTRLUP}") usually

There are a good number of other method to do it (as we can see above). Also if you want to save it as a variable you can use ClipGet()

(If I misunderstood the question then sorry :D )

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