Jump to content

Need help with GUISetAccelerators


Recommended Posts

When i write in inputbox and hit send sends the message, but it also sends when I move the mouse. How can I fix?

(sorry for my bad explanation but I don't know english very well)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Client
#include <GuiConstants.au3>
#include <GuiEdit.au3>

TCPStartup()

$ip=InputBox("Chat","IP:",@IPAddress1,"",50,123) 
If $ip="" Then Exit

$socket=TCPConnect($ip,2000)      
If $socket=-1 Then
       MsgBox(16,"Error","Connection error",5)
       Exit
EndIf

GUICreate("Client",300,240)
$edit=GUICtrlCreateEdit("",0,0,300,200,BitOr($WS_VSCROLL, $ES_READONLY))
$msg=GUICtrlCreateInput("",10,210,200,20)
$send=GUICtrlCreateButton("Send",215,210,80,20)
Dim $AccelKeys[1][2] = [["{ENTER}", $send]]
GUISetAccelerators($AccelKeys)

GUISetState(@SW_SHOW)

While 1
        Switch GUIGetMsg()
            Case $gui_event_close
                GUIDelete()
            Case $send
                $msg1=GUICtrlRead($msg)
                TCPSend($socket,$msg1)
                GUICtrlSetData($msg,"")
        EndSwitch

        $recv=TCPRecv($socket,2048)
        If $recv <> "" Then
                _GUICtrlEdit_AppendText($edit,$recv & @CRLF)
        EndIf
WEnd
Link to comment
Share on other sites

I'm no expert, but I can see three things that might be the problem.

 

  1. Dim $AccelKeys[1][2] = [["{ENTER}", $send]]
    Try removing the brackets '[[ ]]'
  2.  
  3. GUISetAccelerators($AccelKeys)
    Try adding a position to the array  :   GUISetAccelerators($AccelKeys[0][1])
    Or something like that... not sure exactly how those work.
  4.  
  5. GUISetAccelerators($AccelKeys)
    Or try removing this line. In my script I don't even use this.
Link to comment
Share on other sites

  • Moderators

FengHuangWuShen,

None of those are sensible solutions:

  • Removing the brackets will give you a syntax error as they are required when defining a 2D array.
  • If you look in the Help file, you will see that you pass the array name, not a random specific element, to GUISetAccelerators.
  • If you remove the Accelerator key, how do you intend to bind the {ENTER} key to the button?
Quote

not sure exactly how those work

So perhaps not a brilliant idea to offer suggestions then?

Blank517,

Welcome to the AutoIt forums.

I do not get the button Case code firing when I move the mouse - is this the whole code?

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

2 hours ago, Melba23 said:

Blank517,

Welcome to the AutoIt forums.

I do not get the button Case code firing when I move the mouse - is this the whole code?

M23

Thanks for welcome!

Yes, this is the whole code but i have rewrited the entire script...

Now i use:

While 1
    _Recv_data_server()
    If _IsPressed('0D') Then
    _Send()
    EndIf
    Sleep(50)
WEnd

 

Link to comment
Share on other sites

4 hours ago, Melba23 said:

If you remove the Accelerator key, how do you intend to bind the {ENTER} key to the button?

perhaps like this:

GUICtrlSetState($send, $GUI_DEFBUTTON)

 

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

  • Moderators

orbs,

I know of several ways of linking the key to the button - the point was that the responder did not and so the suggestion he made did not offer a sensible solution.

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

Sorry for being a noob and all, but the point of a suggestion is the spark a possible solution, or idea to that solution.

I never said I had the solution, and thanks for the correction, i'll be sure to look further next time. :/ You really are an old timer eh

Additionally, the reason I brought up the no brackets was because of my section of script here ( found on another thread somewhere here ), which has no brackets, only quotations. It is a 2D Array as well.

 

Local $accelerators[1][2]
$accelerators[0][0] = "{ENTER}"
$accelerators[0][1] = $Barcode_Entry


And it worked fine.

 

Edited by FengHuangWuShen
Link to comment
Share on other sites

On 8/24/2016 at 3:07 PM, Blank517 said:

While 1     _Recv_data_server()     If _IsPressed('0D') Then     _Send()     EndIf     Sleep(50) WEnd

While 1
    _Recv_data_server()
    If _IsPressed('0D') Then
        While _IsPressed('0D') ; this way is better
            Sleep(30) ;         it will send on release
        WEnd ;                  avoiding possible problems
    _Send()
    EndIf
    Sleep(50)
WEnd

tho, $msg=GUICtrlCreateInput("",10,210,200,20) would be better with an edit control, and read it and, when you find a @CRLF then, read the contents minus the @CRLF, send, and clear the control ;) 

Edited by argumentum
new idea :)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • Moderators

FengHuangWuShen,

The problem is not "being a noob and all", but being a noob and making suggestions which are completely wrong in terms of basic syntax - which could have been noticed by a cursory glance at the Help file:

; Set GUIAccelerators for the button controlIDs, these being Ctrl + y and Ctrl + n
Local $aAccelKeys[2][2] = [["^y", $idYes], ["^n", $idNo]]
GUISetAccelerators($aAccelKeys)

As you can see:

  • The 2D array needs the double [[ ]] if you assign elements at the same time as declaring the array. In the example you show, the elements are assigned after declaration and so do not need to be enclosed double [[ ]].
  • The GUISetAccelerators command takes the entire array (passed by name) as a parameter and not a single element.

While I agree that suggestions might well spark possible solutions, they need to be based on some degree of reality - which alas yours were not. But please do not get discouraged - do exactly as you suggested and "look further next time" before posting.

M23 (the old timer)

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