Jump to content

Hotkeyset


Recommended Posts

#include <GuiConstants.au3>
#Include <GuiListView.au3>

Opt("GUIOnEventMode",1)

HotKeySet("^a", "select_all_items")

$hMainGUI=GuiCreate("test listview surt FOCUS", 380,300)
GUISetOnEvent($GUI_EVENT_CLOSE,"Exit_GUI")
$Listview_1 =GUICtrlCreateListView("Name|Firstname",20, 10, 160,260,BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
GUICtrlCreateListViewItem("1|Garry", $Listview_1)
GUICtrlCreateListViewItem("1|Jon", $Listview_1)
GUICtrlCreateListViewItem("1|David", $Listview_1)

$Listview_2 =GUICtrlCreateListView("Name|Firstname",200, 10, 160,260,BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
GUICtrlCreateListViewItem("2|Garry", $Listview_2)
GUICtrlCreateListViewItem("2|Jon", $Listview_2)
GUICtrlCreateListViewItem("2|David", $Listview_2)

GuiSetState()

While 1
    Sleep(10)
WEnd

Func Exit_GUI()
    Exit
EndFunc


Func select_all_items()
    Local $opt = Opt("WinTitleMatchMode", 4)
    If WinGetHandle("active") = $hMainGUI Then
        If @HotKeyPressed = "^a" Then 
        _GUICtrlListView_SetItemSelected($Listview_1, -1)
     EndIf
Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "select_all_items")
    EndIf
    Opt("WinTitleMatchMode", $opt)
EndFunc
Hi:

I have a GUI with two listviews. I want to use Hotkeyset to select all items from one of the listview only when the listview has focus. Currently, it is selecting all items from Listview_1 regardless of which listview has the focus. I have no idea how to determine if the Listview_1 has focus or not to give the hotkey function a condition.

Please help me.

Regards

Ajit

Edited by ajit
Link to comment
Share on other sites

I have a GUI with two listviews. I want to use Hotkeyset to select all items from one of the listview only when the listview has focus. Currently, it is selecting all items from Listview_1 regardless of which listview has the focus. I have no idea how to determine if the Listview_1 has focus or not to give the hotkey function a condition.

Hello,

Try this code on your select_all_items function. I think this is a little dirty so wait till an experienced autoit user get back with a better solution :mellow:

Func select_all_items()
    Local $opt = Opt("WinTitleMatchMode", 4)
    If WinGetHandle("active") = $hMainGUI Then
        $ListWithFocus=ControlGetFocus("test listview surt FOCUS");Get Focus
        If $ListWithFocus="SysListView321" then ;the last number 1 is the instance number of the list (check it wit Autoit Window Info)
            $ListWithFocus=$Listview_1
        ElseIf $ListWithFocus="SysListView322" Then
            $ListWithFocus=$Listview_2
        EndIf
        If @HotKeyPressed = "^a" Then
        _GUICtrlListView_SetItemSelected($ListWithFocus, -1)
        EndIf
Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "select_all_items")
    EndIf
    Opt("WinTitleMatchMode", $opt)
EndFunc

Cheers,

sahsanu

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