Jump to content

Paste text tool


lorenkinzel
 Share

Recommended Posts

Recently I was re-doing my push-button recipe book that was lost in "the accident".
It brings up message boxes with recipes or a .txt file if you want to print.
I was getting really bummed about the amount of time spent with copy / paste of "@CRLF &" and "& _".
Lots & lots of lines.
After the first 4 recipes I paused & put this script together. It's not really so much a showcase of amazing coding
as of functionality & "this is a machine job, not a (insert your name) job".
Any improvements or condemnations are welcome.

#include <GUIConstantSex.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{pause}", "pozz")
HotKeySet("1", "startLine"); I'm a numPad guy so I can get away with this
HotKeySet("2", "endLine")
HotKeySet("3", "blankLine")
HotKeySet("4", "eventful")
HotKeySet("5", "copySelection")
HotKeySet("6", "_Mouse_Exit_App")

Global $f_mouse_is_down = False
Global $i_mouse_primary = 0x01; 0x01 = left for primary, 0x02 = right
Global $h_mouse_mod, $h_mouse_timer

$Form1 = GUICreate("", 200, 185, @DesktopWidth - 190, 5)
GUISetBkColor(0x000055, $Form1)
WinSetTrans($Form1, "", 200)

$button1 = GUICtrlCreateButton('@CRLF && " >>start line', 25, 5, 147, 25)
$label1 = GUICtrlCreateButton("1", 1, 5, 15, 25); used as a label but buttons looked nicer
GUICtrlSetBkColor(-1, 0xff0000)
GUICtrlSetColor(-1, 0xffffff)

$button2 = GUICtrlCreateButton('" && _ >>end line', 25, 35, 147, 25)
$label2 = GUICtrlCreateButton("2", 1, 35, 15, 25)
GUICtrlSetBkColor(-1, 0x00ff00)
GUICtrlSetColor(-1, 0xff0000)

$button3 = GUICtrlCreateButton('@CRLF && "" && _ >>blank line', 25, 65, 147, 25)
$label3 = GUICtrlCreateButton("3", 1, 65, 15, 25)
GUICtrlSetBkColor(-1, 0x0000ff)
GUICtrlSetColor(-1, 0xffffff)

$button4 = GUICtrlCreateButton('GUICtrlSetOnEvent(XXX, "XXX")', 25, 95, 170, 25)
$label4 = GUICtrlCreateButton("4", 1, 95, 15, 25)
GUICtrlSetBkColor(-1, 0xff00ff)
GUICtrlSetColor(-1, 0xffffff)

$label5 = GUICtrlCreateButton("5", 1, 125, 15, 25)
GUICtrlSetBkColor(-1, 0xCc7918)
$label5andOneHalf = GUICtrlCreateLabel("copy selected text", 25, 130, 147, 20)
GUICtrlSetColor(-1, 0xffffff)

$label6 = GUICtrlCreateButton("6", 1, 155, 15, 25)
GUICtrlSetBkColor(-1, 0x297777)
GUICtrlSetColor(-1, 0xDcA9A1)
$label6andOneHalf = GUICtrlCreateLabel("shut #5 off", 25, 160, 147, 20)
GUICtrlSetColor(-1, 0xffffff)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button1
            startLine()
        Case $button2
            endLine()
        Case $button3
            blankLine()
        Case $button4
            eventful()
    EndSwitch
WEnd
Func startLine()
    ClipPut("")
    ClipPut('@CRLF & "')
    Send("^v")
EndFunc   ;==>startLine

Func endLine()
    ClipPut("")
    ClipPut('" & _')
    Send("^v")
EndFunc   ;==>endLine

Func blankLine()
    ClipPut("")
    ClipPut('@CRLF & "" & _')
    Send("^v")
EndFunc   ;==>blankLine

Func eventful()
    ClipPut("")
    ClipPut('GUICtrlSetOnEvent(XXX, "XXX")')
    Send("^v")
EndFunc   ;==>eventful

Func pozz();Still on the "to do" list
    MsgBox(0, "paused", "")
    ClipPut("")
EndFunc   ;==>pozz
;notice a change in style between the above & the below?
;========================SmOke_N  section===================================================
;http://www.autoitscript.com/forum/topic/82471-how-to-save-selected-text-to-string/
;post #7 SmOke_N
Func copySelection()
    $h_mouse_timer = _Mouse_StartWatch($h_mouse_mod, "_Mouse_GetHighlight_ToClipboard", "int", "", 0, 10003, 10)
EndFunc   ;==>copySelection

Func _Mouse_GetHighlight_ToClipboard()
    If Not $f_mouse_is_down Then
        Local $a_getasync = DllCall("User32.dll", "int", "GetAsyncKeyState", "int", $i_mouse_primary)
        If Not @error And BitAND($a_getasync[0], 0x8000) = 0x8000 Then
            $f_mouse_is_down = True
            While Not @error And BitAND($a_getasync[0], 0x8000) = 0x8000
                Sleep(50)
                $a_getasync = DllCall("User32.dll", "int", "GetAsyncKeyState", "int", $i_mouse_primary)
            WEnd
            Send("^c")
            Sleep(100)
            $f_mouse_is_down = False
        EndIf
    EndIf
    Return
EndFunc   ;==>_Mouse_GetHighlight_ToClipboard

Func _Mouse_StartWatch(ByRef $h_mod, $s_func, $v_ret_type, $v_params, $h_wnd, $i_event_id, $i_event_time)
    $h_mod = DllCallbackRegister($s_func, $v_ret_type, $v_params)
    If @error Then Return SetError(@error, 1, 0)
    Local $h_timer = DllCall("User32.dll", "int", "SetTimer", _
            "hwnd", $h_wnd, _
            "uint", $i_event_id, _
            "uint", $i_event_time, _
            "ptr", DllCallbackGetPtr($h_mod))
    If @error Then Return SetError(@error, 2, 0)
    Return $h_timer[0]
EndFunc   ;==>_Mouse_StartWatch

Func _Mouse_StopWatch($h_mod, $h_timer, $h_wnd = 0)
    DllCallbackFree($h_mod)
    DllCall("User32.dll", "int", "KillTimer", "hwnd", $h_wnd, "int", $h_timer)
    If @error Then Return SetError(@error, 0, 0)
    Return 1
EndFunc   ;==>_Mouse_StopWatch

Func _Mouse_Exit_App()
    If IsDeclared("h_mouse_mod") Then _Mouse_StopWatch($h_mouse_mod, $h_mouse_timer)
    ;Exit
    ClipPut("")
EndFunc   ;==>_Mouse_Exit_App
;===end post #7 SmOke_N section=============================================================
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...