Jump to content
DarkBoost

HotKey (Ctrl+A) for Select All in the selected Edit Box

Recommended Posts

DarkBoost

Is there a simple way to setup the CTRL+A Hotkey which will select everything in the selected Edit or Input Box?

Not sure how to tackle this without sending a double-mouse click to a specified Edit/Input box which doesn't help as I have multiple Edit/Input boxes.

Quick Example:

#include <GUIConstantsEx.au3>

Opt("MustDeclareVars", 1)

Global $input_left, $input_right

HotKeySet("^a", "_selectall")

GUICreate("", 430, 210)
    $input_left = GUICtrlCreateEdit("here is some text on the left", 10, 10, 200, 190)
    $input_right = GUICtrlCreateEdit("here is some text on the right", 220, 10, 200, 190)
GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _selectall()
;add working code here?
EndFunc
Edited by DarkBoost

Share this post


Link to post
Share on other sites
picea892

try this

If it's not an autoit window

ControlFocus("[CLASS:Notepad]", "", "Edit1")

send("^a")

otherwise

GUICtrlSetState("?HANDLE?", $GUI_FOCUS)

send("^a")

Share this post


Link to post
Share on other sites
DarkBoost

By default CTRL + A is not a working hotkey with AutoIT Edit/Input boxes so send("^a") will do nothing in an AutoIT GUI.

I am trying to recreate the commonly used CTRL + A hotkey with AutoIT to select all the text in the Edit or Input box which is in Focus. There are multiple Edit/Input boxes so I would like the CTRL + A to select the box in focus not just 1 box etc... Hope this is making sense ?

Share this post


Link to post
Share on other sites
BugFix

Why you want to select all in edit/input in your self created form?

Use GuiCtrlRead($ctrl) to get all in this.


Best Regards BugFix  

Share this post


Link to post
Share on other sites
Authenticity

#include <Constants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Dim $hGUI
Dim $Edit, $hEdit
Dim $hFunc, $pFunc, $hWndProc

$hGUI = GUICreate('Test', 200, 200)
$Edit = GUICtrlCreateEdit('123' & @CRLF & '456' & @CRLF & '789', 0, 0, 200, 200)
$hEdit = GUICtrlGetHandle(-1)
$hFunc = DllCallbackRegister('_EditHandler', 'lresult', 'hwnd;uint;wparam;lparam')
$pFunc = DllCallbackGetPtr($hFunc)
$hWndProc = _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $pFunc)
GUISetState()

Do
Until GUIGetMsg() = -3
GUIDelete()
DllCallbackFree($hFunc)
Exit

Func _EditHandler($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iMsg
        Case $WM_CHAR
            ConsoleWrite('WM_CHAR: ' & $iwParam & @LF)
            If $iwParam = 1 Then _SendMessage($hWnd, $EM_SETSEL, 0, -1)
        Case $WM_KEYDOWN
            ConsoleWrite('WM_KEYDOWN: ' & $iwParam & @LF)
        Case $WM_KEYUP
            ConsoleWrite('WM_KEYUP: ' & $iwParam & @LF)
        Case $WM_SYSKEYDOWN
            ConsoleWrite('WM_SYSKEYDOWN: ' & $iwParam & @LF)
        Case $WM_SYSKEYUP
            ConsoleWrite('WM_SYSKEYUP: ' & $iwParam & @LF)
        Case $WM_SYSCHAR
            ConsoleWrite('WM_SYSCHAR: ' & $iwParam & @LF)
    EndSwitch
    
    Return _WinAPI_CallWindowProc($hWndProc, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc

Share this post


Link to post
Share on other sites
DarkBoost

@Authenticity: Perfect thank you kindly!!!

I have again failed to provide enough information as people are not understanding what I am trying to achieve :)

If you open ANYTHING (excluding an AutoIT GUI) which has an input field eg. Notepad, Word, Excel, Email, Internet Explorer Field etc... you can do CTRL + A to select everything in that selected field. You can then do things like CUT, COPY, DELETE etc.

As this feature is not (by default) included when creating GUICtrlCreateEdit or GUICtrlCreateInput in AutoIT I am trying to simply create this as a HotKeySet("^a".... and am not sure how to achieve this. If there is a simple thing I have missed eg. #include <DefaultHotKeySet.au3> I have not been able to find this in the Helpfile or the Forum and wondering if this does exist or how one would recreate this manually if need be.

Edited by DarkBoost

Share this post


Link to post
Share on other sites
martin

@Authenticity: Perfect thank you kindly!!!

I have again failed to provide enough information as people are not understanding what I am trying to achieve :)

If you open ANYTHING (excluding an AutoIT GUI) which has an input field eg. Notepad, Word, Excel, Email, Internet Explorer Field etc... you can do CTRL + A to select everything in that selected field. You can then do things like CUT, COPY, DELETE etc.

As this feature is not (by default) included when creating GUICtrlCreateEdit or GUICtrlCreateInput in AutoIT I am trying to simply create this as a HotKeySet("^a".... and am not sure how to achieve this. If there is a simple thing I have missed eg. #include <DefaultHotKeySet.au3> I have not been able to find this in the Helpfile or the Forum and wondering if this does exist or how one would recreate this manually if need be.

Is this the sort of thing you mean?

#include <GUIConstantsEx.au3>
#include <guiEdit.au3>
#include <editconstants.au3>
#include <windowsconstants.au3>
Opt("MustDeclareVars", 1)

Global $input_left, $input_right, $Gui, $method, $focusedID

HotKeySet("^a", "_selectall")

$Gui = GUICreate("", 430, 210)
$input_left = GUICtrlCreateEdit("here is some text on the left", 10, 10, 200, 190)
$input_right = GUICtrlCreateEdit("here is some text on the right", 220, 10, 200, 190)


GUIRegisterMsg($WM_COMMAND, "MWCOMMAND");before setstate so we know which edit has focus to start with
GUISetState(@SW_SHOW)
$method = 1
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _selectall()
    Switch $method
        Case 1
            ConsoleWrite("using method 1" & @CRLF)
            Send("^{HOME}+^{END}")
        Case 0
            Switch $focusedID
                Case $input_left, $input_right
                    ConsoleWrite("using method 2" & @CRLF)
                    _GUICtrlEdit_SetSel(ControlGetHandle($Gui, "", $focusedID), 0, StringLen(GUICtrlRead($focusedID)))
            EndSwitch

    EndSwitch
    $method = not $method
EndFunc  ;==>_selectall


Func MWCOMMAND($h, $m, $W, $l)
    Local $ID, $iN

    $iN = BitAND($W, 0xffff0000) / 0x10000
    If $iN = $EN_KILLFOCUS Then $focusedID = 0
    $iN = BitAND($W, 0xffff0000) / 0x10000
    If $iN = $EN_SETFOCUS Then $focusedID = BitAND($W, 0xffff)

    Return $GUI_RUNDEFMSG
EndFunc  ;==>MWCOMMAND

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Yashied
martin

@martin

1. You may write a more simple: _GUICtrlEdit_SetSel($focusedID, 0, -1)

2. I think here MWCOMMAND() handler is unnecessary.

Yes thanks Yashied. I forgot about -1 for the whole text, and it's true I need not have passed the handle, but why is WMCOMMAND not needed? Without that I don'y know the value of $focussedID.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Yashied

Yes thanks Yashied. I forgot about -1 for the whole text, and it's true I need not have passed the handle, but why is WMCOMMAND not needed? Without that I don'y know the value of $focussedID.

#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <WinAPI.au3>

Opt("MustDeclareVars", 1)

Global $input_left, $input_right, $hleft, $hright

HotKeySet("^a", "_selectall")

GUICreate("", 430, 210)
$input_left = GUICtrlCreateEdit("here is some text on the left", 10, 10, 200, 190)
$input_right = GUICtrlCreateEdit("here is some text on the right", 220, 10, 200, 190)
$hleft = GUICtrlGetHandle($input_left)
$hright = GUICtrlGetHandle($input_right)
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _selectall()
    Local $hWnd = _WinAPI_GetFocus()
    Switch $hWnd
        Case 0
            
        Case $hleft, $hright
            _GUICtrlEdit_SetSel($hWnd, 0, -1)
            Return
    EndSwitch
    HotKeySet("^a")
    Send("^a")
    HotKeySet("^a", "_selectall")
EndFunc   ;==>_selectall
Edited by Yashied

Share this post


Link to post
Share on other sites
martin

#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <WinAPI.au3>

Opt("MustDeclareVars", 1)

Global $input_left, $input_right, $hleft, $hright

HotKeySet("^a", "_selectall")

GUICreate("", 430, 210)
$input_left = GUICtrlCreateEdit("here is some text on the left", 10, 10, 200, 190)
$input_right = GUICtrlCreateEdit("here is some text on the right", 220, 10, 200, 190)
$hleft = GUICtrlGetHandle($input_left)
$hright = GUICtrlGetHandle($input_right)
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _selectall()
    Local $hWnd = _WinAPI_GetFocus()
    Switch $hWnd
        Case 0
            
        Case $hleft, $hright
            _GUICtrlEdit_SetSel($hWnd, 0, -1)
            Return
    EndSwitch
    HotKeySet("^a")
    Send("^a")
    HotKeySet("^a", "_selectall")
EndFunc   ;==>_selectall
OK, I'm not having a ggod day :)

Thanks again.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Malkey

Using Authenticity's method to select all but activated with the hot keys "Ctrl + A", there is this.

;
 #include <GUIConstantsEx.au3>
 #include <EditConstants.au3>
 #include <WinAPI.au3>
 
 Opt("MustDeclareVars", 1)
 
 Global $input_left, $input_right
 
 HotKeySet("^a", "_selectall")
 
 GUICreate("", 430, 250)
 $input_left = GUICtrlCreateEdit("here is some text on the left", 10, 10, 200, 190)
 $input_right = GUICtrlCreateEdit("here is some text on the right", 220, 10, 200, 190)
 GUICtrlCreateInput("Input data", 10, 210, 150, 25)
 
 GUISetState(@SW_SHOW)
 
 Do
 Until GUIGetMsg() = $GUI_EVENT_CLOSE
 
 Func _selectall()
     _SendMessage(ControlGetHandle("", "", ""), $EM_SETSEL, 0, -1)
 EndFunc  ;==>_selectall
;

Share this post


Link to post
Share on other sites
DarkBoost

wow so many ways to accomplish this, thank you all for your input it has helped alot!

Share this post


Link to post
Share on other sites
Affe

I know this is a bit of an old thread, but I found it useful and wanted to toss in a bit of extra info:

Used the HotKey and _selectall() method.

With other windows forms, there's another default ability to select all when you left-click on an input/edit while holding the control (CTRL) button down. I added this into the While Loop for the GUI itself when using GUIGetMsg():

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN ;Left Mouse Button is pressed, need to check if we are selecting all!
            If _IsPressed(11) Then _selectall() ;"11" is the CTRL button
    EndSwitch
WEnd

Func _selectall()
    _SendMessage(ControlGetHandle("", "", ""), $EM_SETSEL, 0, -1)
EndFunc  ;==>_selectall

Figured someone might find it useful :unsure:

Edited by Affe

[center][/center]

Share this post


Link to post
Share on other sites
dv8

Has anyone noticed that with all these methods the "CTRL+A" combination stops working in all the other windows while this AutoIt script is running?

There has got to be another way to make "CTRL+A" working in the Edit and Input controls. :D

Share this post


Link to post
Share on other sites
Melba23

dv8,

the "CTRL+A" combination stops working in all the other windows

That is because a HotKey has a Global effect so it works all the time. What you need is an Accelerator key - then it will only work when your script is active. :oops:

Take a look at this to see how to do it: :D

#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <WinAPI.au3>
 
Global $hInput_Handle
 
$hGUI = GUICreate("Test", 500, 500)
 
$hInput = GUICtrlCreateEdit("here is some text", 10, 10, 480, 480)
$hInput_Handle = GUICtrlGetHandle(-1)
 
; Create dummy for accelerator key to activate
$hSelAll = GUICtrlCreateDummy()
 
GUISetState()
 
; Set accelerators for Ctrl+a
Dim $AccelKeys[1][2]=[["^a", $hSelAll]]
GUISetAccelerators($AccelKeys)
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hSelAll
            _SelAll()
    EndSwitch
WEnd
 
Func _SelAll()
    Switch _WinAPI_GetFocus()
        Case $hInput_Handle
            _GUICtrlEdit_SetSel($hInput_Handle, 0, -1)
            Return
    EndSwitch
EndFunc   ;==>_SelAll

All clear? :rip:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
dv8

Hmm,

this looks better than the previous suggestions, but still... If I have 10 GUIs with 20 input boxes and 10 Edit boxes each, it will be a PITA to write the _SelAll() function for all of the controls. And I'll have to remember to update this function every time I make a change to the GUI. :D

The question is why CTRL+C and CTRL+V and CTRL+Z etc. are working fine in the inputs and edits but the CTRL+A is not? Is this a bug?

Share this post


Link to post
Share on other sites
Melba23

dv8,

Is this a bug?

Yes, but with Windows Edit controls, not with AutoIt. Google it to find out more. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Zedna

Hmm,

this looks better than the previous suggestions, but still... If I have 10 GUIs with 20 input boxes and 10 Edit boxes each, it will be a PITA to write the _SelAll() function for all of the controls. And I'll have to remember to update this function every time I make a change to the GUI. :D

Here is efect universal solution for all edit controls in GUI

#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <WinAPI.au3>
 
$hGUI = GUICreate("Test", 500, 500)
 
$hInput1 = GUICtrlCreateEdit("here is some text 1", 10, 10, 480, 240)
$hInput2 = GUICtrlCreateEdit("here is some text 2", 10, 250, 480, 240)
 
; Create dummy for accelerator key to activate
$hSelAll = GUICtrlCreateDummy()
 
GUISetState()
 
; Set accelerators for Ctrl+a
Dim $AccelKeys[1][2]=[["^a", $hSelAll]]
GUISetAccelerators($AccelKeys)
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hSelAll
            _SelAll()
    EndSwitch
WEnd
 
Func _SelAll()
    $hWnd = _WinAPI_GetFocus()
    $class = _WinAPI_GetClassName($hWnd)
    If $class = 'Edit' Then _GUICtrlEdit_SetSel($hWnd, 0, -1)
EndFunc   ;==>_SelAll
Edited by Zedna
  • Like 3

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.