How to detect keypress event on a control?

Get help with using AutoHotkey and its commands and hotkeys
afe
Posts: 145
Joined: 06 Dec 2018, 04:36

How to detect keypress event on a control?

14 Jan 2019, 10:58

Hello,
I tried to use "OnMessage" to detect keypress events on the combo box to execute different code depending on whether a keypress event occurred., But it didn't work. I don't know what went wrong? Is this approach feasible or is there a better way?

Thanks.

Code: Select all

Gui Add, ComboBox, w200 section gMyComboBox HWNDComboBoxHWND vMyComboBox
Gui, Add, Button, ys section HWNDRefreshHWND vRefresh, ↻
Gui Show
return


MyComboBox:
r := OnMessage(0x0100, "KEYDOWN")

if ( r = 1)
	GuiControl,, %RefreshHWND%, →
else if ( r = 0 )
	Gui, Submit, NoHide
return


KEYDOWN(wParam, lParam, Msg,HWND)
{
	Global ComboBoxHWND

	if ( HWND = ComboBoxHWND )
		return, 1

	return, 0
}
Hellbent
Posts: 238
Joined: 23 Sep 2017, 13:34

Re: How to detect keypress event on a control?

14 Jan 2019, 12:57

This works, but i'm sure someone else will come along with a better solution.

Code: Select all

#SingleInstance,Force
OnMessage(0x0100, "KEYDOWN")
global ComboBoxVar , r := 0 , dummyedit

Gui Add, ComboBox, w200 section gMyComboBox vComboBoxVar ,item 1|item 2|
Gui, Add, Button, ys w30 section HWNDRefreshHWND vRefresh, ?
gui,add,edit,x10 w200 vdummyedit gMyComboBox
Gui Show, w300 h200
return
GuiClose:
	ExitApp

MyComboBox:
if ( r = 1){
	Tooltip, you typed in the combobox
	r := 0
	GuiControl,, %RefreshHWND%, Go
}
else if ( r = 0 ){
	Tooltip, you clicked a item in the combobox `nor typed in some other control
	Gui, Submit, NoHide
	GuiControl,, %RefreshHWND%, ?
}
return

KEYDOWN(wParam, lParam, Msg,HWND){
	GuiControlGet,oName,Name,%HWND%
	r := (oName = "ComboBoxVAR")?(1):(0)
}
teadrinker
Posts: 417
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to detect keypress event on a control?

14 Jan 2019, 14:37

Hi,

Code: Select all

Gui, Add, ComboBox, vComboBox, Item1||Item2|Item3
Gui, Add, Edit, vEdit
Gui, Show
OnMessage(0x100, "WM_KEYDOWN")
Return

WM_KEYDOWN(wp, lp)  {
   ; vk := Format("{:X}", wp)
   sc := Format("{:X}", (lp >> 16) & 0x1FF)
   ToolTip % A_GuiControl "`n" GetKeyName("sc" . sc)
}

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Google [Bot], Haasjes, jony26, SOTE and 63 guests