Jump to content

Input without preselected item


Recommended Posts

When an input contains a default value, and the program focuses on that input, the value is automatically selected, so when the user begins to type, it is cleared.

My question: how to remove the auto-selection?

Here a simple code

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


$hWnd = GUICreate("Input without preselected input", 400, 300)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 260, 248, 80, 30, 0)
$input1 = GUICtrlCreateInput("Value1", 20, 24, 200, 24)
$input2 = GUICtrlCreateInput("Value2", 20, 80, 200, 24)

GUISetState()
GUICtrlSetState($input2, $GUI_FOCUS) ; here we focus to the second input

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

  • Moderators

charvi,

Send a "HOME" after setting the focus:

GUICtrlSetState($input2, $GUI_FOCUS); here we focus to the second input
Send("{HOME}")

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 also can use GUICtrlSendMsg with $EM_SETSEL (it's more reliable that way):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
;

$hWnd = GUICreate("Input without preselected input", 400, 300)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 260, 248, 80, 30, 0)
$input1 = GUICtrlCreateInput("Value1", 20, 24, 200, 24)
$input2 = GUICtrlCreateInput("Value2", 20, 80, 200, 24)

GUISetState()

GUICtrlSetState($input2, $GUI_FOCUS) ; here we focus to the second input
GUICtrlSendMsg($input2, $EM_SETSEL, -1, -1) ; and here we set the selection at the end of input control

While 1
    $nMsg = GUIGetMsg()
   
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

You also can use GUICtrlSendMsg with $EM_SETSEL (it's more reliable that way):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
;

$hWnd = GUICreate("Input without preselected input", 400, 300)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 260, 248, 80, 30, 0)
$input1 = GUICtrlCreateInput("Value1", 20, 24, 200, 24)
$input2 = GUICtrlCreateInput("Value2", 20, 80, 200, 24)

GUISetState()

GUICtrlSetState($input2, $GUI_FOCUS) ; here we focus to the second input
GUICtrlSendMsg($input2, $EM_SETSEL, -1, -1) ; and here we set the selection at the end of input control

While 1
    $nMsg = GUIGetMsg()
   
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd
Thank you for your reply MrCreatoR, this is indeed a good thing to know too.

But what is the real difference/advantage with the use of GUICtrlSendMsg() against Send()? Your example also works with the more human-readable Send("{End}"). You told it's more reliable, does this mean that Send() is not reliable enough in some circumstances?

For example, when I make an input where I'm giving the user a typing facility by locating the caret at the 5th position, I'm using the Melba23 idea (in the case a number for 95% should begin with '555-'):

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

$hWnd = GUICreate("Input with caret at desired position", 350, 130)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 218, 70, 80, 30, 0)
GUICtrlCreateLabel("Number: ", 20, 24, 200, 20)
$input1 = GUICtrlCreateInput("555-123-456", 100, 22, 200, 24)

GUISetState()
GUICtrlSetState($input1, $GUI_FOCUS)
Send("{Home}{Right}{Right}{Right}{Right}")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

But what is the real difference/advantage with the use of GUICtrlSendMsg() against Send()? Your example also works with the more human-readable Send("{End}"). You told it's more reliable, does this mean that Send() is not reliable enough in some circumstances?

It's obvious - Send message directly to the control will garantee a success, it's a dircet interaction with the control :)

And via Send() keys can be sent to other window that is currently active (by user or other app).

For example, when I make an input where I'm giving the user a typing facility by locating the caret at the 5th position, I'm using the Melba23 idea

You can do the same with GUICtrlSendMsg:

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

$hWnd = GUICreate("Input with caret at desired position", 350, 130)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 218, 70, 80, 30, 0)
GUICtrlCreateLabel("Number: ", 20, 24, 200, 20)
$input1 = GUICtrlCreateInput("555-123-456", 100, 22, 200, 24)

GUISetState()

GUICtrlSetState($input1, $GUI_FOCUS)
GUICtrlSendMsg($input1, $EM_SETSEL, 4, 4) ;first parameter (4) is the end of selection position, and the second is the start of selection position

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEndoÝ÷ Ø    ÝnÜ0Ølzwr¢çhm綬y Þ-g¬Êjwhë-¶¬jëh×6Send("{Home}{Right 4}")

And one more thing; instead of Send you could use «ControlSend()», wich is also direct interaction with the control.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

MrCreatoR,

Thank you for your understandable explanations, and for the remark in the line

GUICtrlSendMsg($input1, $EM_SETSEL, 4, 4) ;first parameter (4) is the end of selection position, and the second is the start of selection position

as well for the additions about {Right 4}.

I will try to use GUICtrlSendMsg() instead of Send() from now on.

As you perhaps have seen in my parallel posting http://www.autoitscript.com/forum/index.php?showtopic=95809 I still have a problem with Insert/Overwrite toggle method. Thanubis said there that it is not possible to get this behavior in a standard input field. Is there a workaround with GUICtrlSendMsg() or with a DLL call? Jos' example worked there because the SciTE Editor supports this toggle mode.

Beside that, I also need to know in which position the Ins/Ovw is toggled (result as a Boolean value).

And in an hour or three, I will post a new topic 'DOS alike Input Editor' with code that I was trying to write during the first days of this year... but abandoned because of typing problems. But it will show what I would like to obtain as a final Function.

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