Jump to content

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


Recommended Posts

  • Moderators

Zedna,

I have been puzzling over how to do that! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

dv6,

What "other inputs"? This works for all "Edit"-class controls in the GUI. :D

Post an example GUI where it does not work for you and we will try and debug it. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

You are absolutely right! I'm really sorry! I spoke before I tested it properly. The previous solution was working fine for the EDIT fields but messed up the CTRL+A functionality for the INPUT fields.

This one is actually working without these side effects.

I apologize again!

Thank you Zedna! If you ever plan a trip to Plovdiv, Bulgaria, send me a PM and I'll be glad to meet and buy you a lunch or dinner! :D

Edited by dv8
Link to comment
Share on other sites

  • 11 months later...

I was just working with this in another program, and noticed I had posted a solution here earlier that I ended up using without noticing I posted it!

Anyhoo, I found another way to use hotkeys without having to use accelerators to still make Ctrl+A work in all windows (only relevant code shown, code for GUI and everything else omitted):

#Include <Misc.au3>
#Include <SendMessage.au3>
#include <WinAPI.au3>

Global $hotkeyset = False

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case ;yada yada yada
            
        Case ;yada yada yada
            
    EndSwitch
    
    ;check for select all hotkey so it doesnt disable other windows
    If _WinAPI_GetForegroundWindow() == WinGetHandle($Parent_GUI) Or _WinAPI_GetForegroundWindow() == WinGetHandle($Child_GUI) Then
        If $hotkeyset = False Then _sethotkeys(True)
    Else
        If $hotkeyset = True Then _sethotkeys(False)
    EndIf
WEnd

Func _sethotkeys($toggle = True)
    If $toggle Then
        HotKeySet("^a", "_selectall")
    Else
        HotKeySet("^a")
    EndIf
    $hotkeyset = $toggle
EndFunc

Func _selectall()
    $hWnd = _WinAPI_GetFocus()
    $class = _WinAPI_GetClassName($hWnd)
    _SendMessage($hWnd, $EM_SETSEL, 0, -1)
EndFunc  ;==>_selectall

Essentially, in the main While loop, you have the program check if your GUI is the foreground window. If it isn't, the hotkeys are disabled, and if it is, they are re-enabled. I used two GUI's in this example to show a parent and a child, though you can have as many or as few as you like of course.

Edited by Affe

[center][/center]

Link to comment
Share on other sites

  • 4 months later...

without external libraries for doing the work:

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>

Global $input_left, $input_right, $hleft, $hright, $Flag = 1, $Flag2 = 1
GUICreate("Test", 430, 210)
$input_left = GUICtrlCreateInput("here is some text on the left", 10, 10, 200, 19)
$input_right = GUICtrlCreateInput("here is some text on the right", 220, 30, 200, 19)
$hleft = GUICtrlGetHandle($input_left)
$hright = GUICtrlGetHandle($input_right)
GUISetState()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYDOWN
$aCurPos = GUIGetCursorInfo()
If $aCurPos <> 0 Then
If $aCurPos[4] = $input_left And $Flag = 1 Then
GUICtrlSetState($input_left,$GUI_FOCUS)
GUICtrlSendMsg($hleft,0xB1,0,-1) ;$EM_SETSEL = 0xB1
$Flag = 0
ElseIf $aCurPos[4] <> $input_left And $Flag = 0 Then
$Flag = 1
EndIf
If $aCurPos[4] = $input_right And $Flag2 = 1 Then
GUICtrlSetState($input_right,$GUI_FOCUS)
GUICtrlSendMsg($hright,0xB1,0,-1) ;$EM_SETSEL = 0xB1
$Flag2 = 0
ElseIf $aCurPos[4] <> $input_right And $Flag2 = 0 Then
$Flag2 = 1
EndIf
EndIf
EndSwitchWEnd

For EditCtrls this way won't work, may the parameter $EM_SETSEL (0xB1) need to be changed...

PS: I used a gui posted here and I don't know tidy this for this forum :/

Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

  • 2 years later...

Any Edit Class = Edit e InputBox

The problem is basically implement Ctrl+a to the Edit Control to Select All

This worked well using GUIGetMsg () but when working with GUIOnEventMode this does not work

Below implementation to intercept Ctrl+a and Enter keys

Create dummy for accelerator key to activate
$cSelAll = GUICtrlCreateDummy()
$cEnter = GUICtrlCreateDummy()
; Set accelerator for Ctrl+a , This intercepts all controls including InputBox
Dim $aAccelKeys[][]=[["^a", $cSelAll],["{enter}", $cEnter]]
GUISetAccelerators($aAccelKeys
)

The program below allows you to change the GUIGetMsg() Mode <=> GUIOnEventMode simply changing the CheckBox

26/01/2016
PROBLEM SOLVED,  GUICtrlGetHande($id) returns 0 for Dummy Controls and a Was not seting the event

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         Elias Assad Neto

 Script Function:
    Teste Ctrl+a To Select All text in Edit Control

 Problem: DOESN'T work in GUIOnEvent

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


Global $EventMode = False ; Start Mode
If $EventMode Then Opt("GUIOnEventMode", 1)

#Region GUI
#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("Ctrl+a Select All Test", 502, 502, 192, 125)
$idCBGUIOnEvent = GUICtrlCreateCheckbox("GUIOnEvent Test", 8, 10, 105, 17)
$idLabelInput = GUICtrlCreateLabel("Input Box", 136, 12, 49, 17)
$idLabelEdit = GUICtrlCreateLabel("Edit Control", 12, 32, 58, 17)
$idInput = GUICtrlCreateInput("Ctrl+a Stop Workin with OnEvent", 192, 10, 289, 21)
$idEdit1 = GUICtrlCreateEdit("", 10, 50, 480, 440)
GUICtrlSetData(-1, "here is some text, Ctrl+a Only Whorks if Not in GUIOnEventMode Mode")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; Create dummy for accelerator key to activate
$cSelAll = GUICtrlCreateDummy()
$cEnter = GUICtrlCreateDummy()

; Set accelerator for Ctrl+a , This intercepts all controls  including InputBox
Dim $aAccelKeys[][]=[["^a", $cSelAll],["{enter}", $cEnter]]
GUISetAccelerators($aAccelKeys)


If 1 Then ; Crate Events for All Controls It Works in Not GUIOnEventMode too
    For $id=-13 To -3 ; $GUI_EVENT_DROPPED(-13) to $GUI_EVENT_CLOSE(-3)
        GUISetOnEvent($id, "GUIEvent")
    Next
    $id = 3 ; Controls Start at id = 3
    $k = 0 ; Limit Couter
    Do
        $h = GUICtrlGetHandle($id) ; test if control exist
        If $h <> 0 Then ; Is Control
            GUICtrlSetOnEvent($id, "GUIEvent") ; Id Has Contro Set Event
        Else
            $k +=1 ; Id has no control this can hapen if control is deleted
        EndIf
        $id +=1
    Until $k > 20 ; No more Controls
EndIf

If $EventMode Then _CheckBox($idCBGUIOnEvent,1)


#Region Program LOOP ===============================================================================================
While 1
    If $EventMode Then
        Sleep(100)
    Else
        GUI_Msg(GUIGetMsg())
    EndIf
WEnd
Func GUIEvent() ; Event Parser
    GUI_Msg(@GUI_CtrlId)
EndFunc
#EndRegion Program LOOP ===============================================================================================

#Region GUI Process messages/Event
Func GUI_Msg($GUI_CtrlId) ; Process GUI Message or Event
    If $GUI_CtrlId = 0 Then Return
    If $EventMode Then
        Local $GUI_WinHandle = @GUI_WinHandle, $GUI_CtrlHandle = @GUI_CtrlHandle
    Else
        Local $GUI_WinHandle = $hGUI,  $GUI_CtrlHandle = GUICtrlGetHandle($GUI_CtrlId)
    EndIf
    If $GUI_CtrlId > 0 Then ConsoleWrite(StringFormat("> $GUI_CtrlId: %3d,   @GUI_WinHandle: 0x%08X, @GUI_CtrlHandle: 0x%08X\n",$GUI_CtrlId, $GUI_WinHandle, $GUI_CtrlHandle))
    Switch $GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cSelAll
            _SelAll()
        Case $cEnter
            _EnterKey()
        Case $idCBGUIOnEvent
            $EventMode = _CheckBox($idCBGUIOnEvent)
            If $EventMode Then
                Opt("GUIOnEventMode", 1) ; Switch to GUIOnEvent
            Else
                Opt("GUIOnEventMode", 0) ; Switch to GUIGetMsg
            EndIf
    EndSwitch
EndFunc
#Region GUI Process messages/Event

#Region GUI Aux Funcs
Func _CheckBox($idControlID, $State = -1) ; (-1)-Read, (0)-Uncheck CheckBox (1)-Check ; Return State
    If $State = 0 Then GUICtrlSetState($idControlID, $GUI_UNCHECKED)
    If $State = 1 Then GUICtrlSetState($idControlID, $GUI_CHECKED)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_CheckBox


Func _SelAll() ; Select All, used for Inbox and Edit controls Intercept Ctrl+a
    Local $hFocus = _WinAPI_GetFocus()
    Local $sClass = _WinAPI_GetClassName($hFocus)
    ConsoleWrite(StringFormat("- Class: %-12s $hFocus: 0x%08X\n", $sClass, $hFocus))
    If $sClass = "Edit" Then _GUICtrlEdit_SetSel($hFocus, 0, -1)
EndFunc   ;==>_SelAll

Func _EnterKey() ; Shows the control's text by pressing Enter on Edit or Inbox Control
    Local $hFocus = _WinAPI_GetFocus()
    Local $sClass = _WinAPI_GetClassName($hFocus)
    ConsoleWrite(StringFormat("- Class: %-12s $hFocus: 0x%08X\n", $sClass, $hFocus))
    If $sClass = "Edit" Then MsgBox(0,"Enter pressed",_GUICtrlEdit_GetText($hFocus))
EndFunc   ;==>_SelAll
#EndRegion GUI Aux Funcs

 

Edited by Elias
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...