Jump to content

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


 Share

Go to solution Solved by somdcomputerguy,

Recommended Posts

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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

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

Link to comment
Share on other sites

  • Moderators

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.

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...