In order to use the return key in ListView, you must replace its default WindowProc procedure as follows. Func _WindowProc($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_GETDLGCODE
Switch $wParam
Case $VK_RETURN
Return $DLGC_WANTALLKEYS
EndSwitch
EndSwitch
Return _WinAPI_CallWindowProc($pDefWindowProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc ;==>_WindowProc But unfortunately DllCallbackRegister() will not work properly here. But you can write your own DLL. Global Comctl32.l = OpenLibrary(#PB_Any, "comctl32.dll")
ProcedureDLL.i SubclassProc(*HWnd, Msg.l, *WParam, *LParam, *ID, *IParam)
Select Msg
Case #WM_GETDLGCODE
Select *WParam
Case #VK_RETURN
ProcedureReturn #DLGC_WANTALLKEYS
EndSelect
EndSelect
ProcedureReturn CallFunction(Comctl32, "DefSubclassProc", *HWnd, Msg, *WParam, *LParam)
EndProcedure WSP.dll And a simple example. #Include <APIConstants.au3>
#Include <GUIListView.au3>
#Include <GUIConstantsEx.au3>
#Include <ListViewConstants.au3>
#Include <WinAPIEx.au3>
OnAutoItExitRegister('AutoItExit')
$hForm = GUICreate('MyGUI', 300, 300)
$hLV = GUICtrlGetHandle(GUICtrlCreateListView('Name', 0, 0, 300, 300, -1, 0))
For $i = 1 To 4
_GUICtrlListView_AddItem($hLV, 'Item' & $i)
Next
$hDll = _WinAPI_LoadLibrary(@ScriptDir & 'WSP.dll')
If $hDll Then
$pSubclassProc = _WinAPI_GetProcAddress($hDll, 'SubclassProc')
If Not @error Then
_WinAPI_SetWindowSubclass($hLV, $pSubclassProc, 1000)
Else
_WinAPI_FreeLibrary($hDll)
EndIf
EndIf
$Dummy = GUIctrlCreateDummy()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()
While 1
Switch GUIGetMsg()
Case 0
ContinueLoop
Case $GUI_EVENT_CLOSE
Exit
Case $Dummy
MsgBox(0, '', _GUICtrlListView_GetItemText($hLV, GUICtrlRead($Dummy)) & ' is activated.')
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $tNMIA = DllStructCreate($tagNMITEMACTIVATE, $lParam)
Local $hTarget = DllStructGetData($tNMIA, 'hWndFrom')
Local $ID = DllStructGetData($tNMIA, 'Code')
Switch $hTarget
Case $hLV
Switch $ID
Case $LVN_ITEMACTIVATE
Local $Item = DllStructGetData($tNMIA, 'Index')
If _GUICtrlListView_GetItemSelected($hLV, $Item) Then
GUICtrlSendToDummy($Dummy, $Item)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func AutoItExit()
If $pSubclassProc Then
_WinAPI_RemoveWindowSubclass($hLV, $pSubclassProc, 1000)
EndIf
EndFunc ;==>AutoItExit @Melba23 Yes it works, but it has several drawbacks: _GUICtrlListView_GetSelectedIndices() may be too slow for a large number of items.You should check the current focus.