Sign in to follow this  
Followers 0
maikelmeyers

How to control keys in a gui?

5 posts in this topic

Hi,

can anyone tell me how to control keys in a gui? For example: if I press ESC the gui closes. How can I avoid this? Second example: If a combobox is in focus, how is it possible to do some action when ENTER is pressed. Is it possible to get a message? In the moment if I press ENTER it activates another checkbox which has not the focus. I don't find any functions related to keyboard except hotkeyset, but this is not usable because then you can not run multiple instances of that script.

Share this post


Link to post
Share on other sites



Opt("GUICloseOnESC", 0)

thanks, first question solved :P

but I think I found a bug. Please have a look at the following example code. First click on the combobox and press ENTER. A message box will be displayed telling you the current focus. It is "Edit1". That is ok. Now press on the button. A message box informs you that the button was pressed. Then the button turns green. NOW, click the combobox and press ENTER again. Now both Items seems to be pressed, although the combobox has the focus. Why?

CODE

#Include <Misc.au3>

#include <GUIConstants.au3>

#include <WindowsConstants.au3>

#Include <GuiButton.au3>

$gui_window_main = GUICreate ("Test",500,500,100,100,$WS_SYSMENU)

$gui_button = GUICtrlCreateButton ("test button",0,0,200,200)

$gui_combo = GUICtrlCreateCombo ( "test combo",0,250,200,200)

GUISetState (@SW_SHOW)

while 1

if(_IsPressed("0D")) then

MsgBox(1,"",ControlGetFocus ($gui_window_main))

endif

$msg = GUIGetMsg(1)

if($msg[0] = 0) then

ContinueLoop

endif

if ($msg[1] = $gui_window_main) then

if ($msg[0] = $gui_button) then

MsgBox(1,"","button pressed")

GUICtrlSetBkColor ( $gui_button, 0x88ff88 )

elseif $msg[0] = $GUI_EVENT_CLOSE then

guidelete()

endif

endif

wend

Share this post


Link to post
Share on other sites

This does not happen when GUICtrlSetBkColor is not used

Share this post


Link to post
Share on other sites

use GUISetAccelerators to set a dummy control to ENTER. Then, in the Case / Func of the dummy you can make custom Handling for ENTER key on your gui :P


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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