Sign in to follow this  
Followers 0
rajeshwaran

How to handle UP & DOWN keys in Input Box

5 posts in this topic

In linux command prompt, if you press UP/DOWN keys it will display the previous commands which are executed.

Like that, I am also trying to do the same with Input Box.

But I do not know, how to handle UP/DOWN keys for InputBox. From AutoIt help for the function "GUIRegisterMsg" I came to know the below

"Some controls consume internally specific Windows Message ID, so registrating them will have no effect, e.g; WM_CHAR, WM_KEYDOWN, WM_KEYUP are consumed by an edit control."

Any other way to resolve this problem ?

Share this post


Link to post
Share on other sites



I don't think you can do this with an actual inputbox as that's a blocking function, but you caould make your own inputbox function with the functionality.

Here's an example that should be editable to how you want it:

#include<array.au3>
Global $aCommands[5] = ["command1","command2","command3","command4","command5"] ;this is just some fake history for testing
Global $iHistory = UBound($aCommands) ;keeps track of the currently displayed history item

Global $hWnd = GUICreate("test",420)
Global $CtrlInput = GUICtrlCreateInput("",10,10,400,20)
GUICtrlCreateEdit("This edit does nothing.",10,40,400,200)
Global $hInput = ControlGetHandle($hWnd,"",$CtrlInput)
GUISetState()

HotKeySet("{Up}","_PrevCMD")
HotKeySet("{Down}","_NextCMD")

While 1
    Switch GUIGetMsg()
 Case -3
 Exit
 Case $CtrlInput
 _RunCommand()
 GUICtrlSetData($CtrlInput,"")
 _ArrayDisplay($aCommands)
    EndSwitch
WEnd

Func _RunCommand()
    $sCMD = GUICtrlRead($CtrlInput)
    _ArrayPush($aCommands,$sCMD) ;using this as a limited history, _Arrayadd can be used as unlimited history until max arraysize is reached.
    $iHistory = UBound($aCommands) ;reset the history position
    ;execute command
EndFunc

Func _PrevCMD() ;go to command executed before the curerntly displaying one
    If ControlGetHandle($hWnd,"",ControlGetFocus($hWnd)) <> $hInput Then Return ;only make it work when the input is focussed
    If $iHistory = 0 Then
 $iHistory = UBound($aCommands) - 1 ;once the end is reached it goes back to the start
    Else
 $iHistory -= 1
    EndIf
    GUICtrlSetData($CtrlInput,$aCommands[$iHistory])
EndFunc

Func _NextCMD() ;go to the command executed after the currently displaying one
    If ControlGetHandle($hWnd,"",ControlGetFocus($hWnd)) <> $hInput Then Return
    If $iHistory >= UBound($aCommands) - 1 Then
 $iHistory = 0 ;once the start is reached it goes back to the end
    Else
 $iHistory += 1
    EndIf
    GUICtrlSetData($CtrlInput,$aCommands[$iHistory])
EndFunc

Share this post


Link to post
Share on other sites

rajeshwaran,

No doubt there is a sexy way to do it with GUIRegisterMsg, but you can also do it like this: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>

Global $aInputs[9], $iIndex = 0

$dll = DllOpen("user32.dll")

$hGUI = GUICreate("Test", 500, 500)

$hInput = GUICtrlCreateInput("", 10, 10, 200, 20)

$hButton = GUICtrlCreateButton("Input", 10, 50, 80, 30)

$hLabel = GUICtrlCreateLabel("", 10, 100, 400, 40)
GUICtrlSetFont(-1, 18)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $hButton
            If GUICtrlRead($hInput) <> "" Then
                GUICtrlSetData($hLabel, GUICtrlRead($hInput))
                _ArrayPush($aInputs, GUICtrlRead($hInput), 1)
            EndIf
    EndSwitch

    If _IsPressed("28", $dll) = 1 Then
        ; DOWN Arrow
        If $iIndex > 0 Then
            $iIndex -= 1
            GUICtrlSetData($hInput, $aInputs[$iIndex])
        EndIf
        While _IsPressed("28", $dll) = 1
            Sleep(10)
        WEnd
    EndIf
    If _IsPressed("26", $dll) = 1 Then
        ;   UP Arrow
        If $iIndex < 9 Then
            If $aInputs[$iIndex + 1] <> "" Then
                $iIndex += 1
                GUICtrlSetData($hInput, $aInputs[$iIndex])
            EndIf
        EndIf
        While _IsPressed("26", $dll) = 1
            Sleep(10)
        WEnd
    EndIf

WEnd

All clear? :)

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

Hi Melba,

Thank you very much.

Your way of thinking is different.

Thank you, once again.

Share this post


Link to post
Share on other sites

rajeshwaran,

Your way of thinking is different

You are by no means the first to say that! ;)

:)

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

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
Sign in to follow this  
Followers 0