Jump to content

How to set attention to input box and activate on Enter.


 Share

Recommended Posts

Can someone help me with this code... I got all of it working with exception of 2 things.

1. Upon loading I want to set the cursor in the input box ready to type.

2. add the additional method of submit by hitting enter to submit also as speed is improtant.

Thanks I am sure this is a piece of cake for most of you pros.. if you need to see an image which I doubt just place any image named image\image.jpg width=300 and height=70 .. but you should not need that.... Thanks...

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <SendMessage.au3>

Global Const $SC_DRAGMOVE = 0xF012
$title=""
$width  = 330
$height = 130
$left   = 600
$top    = 100
$gui = GUICreate($title, $width, $height, $left, $top, $WS_POPUP)
GUISetBkColor(0xE0FFFF)
$n = GUICtrlCreatePic(@ScriptDir & "\image\image.jpg", 10, 10, 310, 75)
GUISetState()
$title=""
$width  = 200
$height = 20
$left   = 10
$top    = 95
$str = GUICtrlCreateInput($title, $left, $top, $width, $height)
$title="Submit"
$width  = 80
$height = 20
$left   = 240
$top    = 95
$press=GUICtrlCreateButton($title, $left, $top, $width, $height)

_WinAPI_SetLayeredWindowAttributes($gui, 0x01, 255)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_MINIMIZE
    GUISetState(@SW_RESTORE)
Case $press
MsgBox(4096, "No Drag Drop.", GUICtrlRead($str))
Exit
Case $GUI_EVENT_PRIMARYDOWN
_SendMessage($gui, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndSwitch
WEnd
Link to comment
Share on other sites

ControlFocus ($gui, "", $str)

I don't read all the topic, if you want to send something use ControlSend

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

  • Moderators

tommytx,

Add these lines between the GUISetState and While lines:

; Set the keyboard focus to the input
GUICtrlSetState($str, $GUI_FOCUS)

; Set an accelerator key - ENTER will fire $press
Local $aAccelKeys[1][2] = [["{ENTER}", $press]]
GUISetAccelerators($aAccelKeys)

Look at the functions in the Help file and ask if you still have questions. :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

Thanks Diogo.. that worked great for the first question.. the attention to the input box...

I just thought of a way to do item 2. Make the input box submit when enter is hit also.. Not sure if its the correct or best way but here it is.. If anyone has a simpler or better idea please chime in.. meantime this will work.. but I doubt its the official Autoit way...anyway see it below...

<

HotKeySet("{ENTER}", "Submit")

Func Submit()

MsgBox(4096, "No Drag Drop.", GUICtrlRead($str))

Exit

EndFunc

>

Link to comment
Share on other sites

  • Moderators

tommytx,

Take a look at my post above - you were close but Accelerator keys work better for this sort of thing as they are only active when your GUI is active. :oops:

Making an input fire on an ENTER key press is not as easy as you might think, but it can be done - search the forum. :bye:

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

Thanks for that Melba, you are right.. the Accelerator works much better... can you tell me how to Dim this so I can add it to my Dim's at the top of the page.. Since it would not work till I place it far down into the code... how do i add the sucker to my Dim

maybe like this.. Dim $aAccelKeys or Dim $aAccelKeys[][] etc?

Then just use this down later... $aAccelKeys[2][2]=[["{ENTER}", $press]

When I put it toward the top it did not work...

_WinAPI_SetLayeredWindowAttributes($gui, 0x01, 255)

GUISetState(@SW_SHOW)

Dim $aAccelKeys[2][2]=[["{ENTER}", $press]

GUISetAccelerators($aAccelKeys)

Link to comment
Share on other sites

  • Moderators

tommytx,

You just need to declare the name at the top of the script - no need for [ ][ ]: :oops:

Global $aAccelKeys

Do not use Dim - it is essentially deprecated. The Variables - using Global, Local and ByRef tutorial in the Wiki explains why. :doh:

As to keeping the GUI on top - either use the $WS_EX_TOPMOST style or the WinSetOnTop function. :bye:

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

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