A_GuiEvent only reacts to mouseclick not to arrow keys/tab etc Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

A_GuiEvent only reacts to mouseclick not to arrow keys/tab etc

14 Mar 2018, 07:36

Hi guys,

I'm having a little issue with gui controls not updating when using the arrow keys in a listview.
The documentation is saying:

The type of event that launched the current thread. If the thread was not launched via GUI action, this variable is blank. Otherwise, it contains one of the following strings:

Normal: The event was triggered by a single left-click or via keystrokes (arrow keys, TAB key, space bar, underlined shortcut key, etc.). This value is also used for menu bar items and the special events such as GuiClose and GuiEscape.


But when I use arrow keys in the listview for instance, the gui controls do not get updated, they only do by left clicking.
It's not a huge issue, but it kinda annoys me that I cannot get it working.

Here's a snippet of my code (full code below):

Code: Select all

MyListView:
if A_GuiEvent = Normal
{
	CurrentColumn = %A_EventInfo%
	LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
	FileRead, Werknemers, werk.csv
	Loop, Parse, Werknemers , `n, `r ,%A_Space%
	{
	If ( A_Index ) = 1 ; skip column names
	{
		Continue
	}
			
	StringSplit, data, A_LoopField, `; ,%A_Space%
	SearchString = %data2%`, %data3%
	if (SearchString = RowText)
	{
		SearchString = %data2%`, %data3%
		GuiControl, enable, Bewerken
		GuiControl, ,Werknemersnummer, %data1%
		GuiControl, ,Voornaam, %data3%
		GuiControl, ,Achternaam , %data2%
		GuiControl,, GeboorteDatum, % MyFunction(data24)
		if ( data23 = "Mannelijk" )
		{
			GuiControl,Choose, Geslacht, 1
		}
		else
		{
			GuiControl,Choose, Geslacht, 2
		}
		GuiControl, ,Adres , %data4%
		GuiControl, ,Postcode, %data6%
		GuiControl, ,Woonplaats , %data5%
		GuiControl, ,Telefoonnummer , %data7%
		GuiControl, ,Mobielnummer , %data8%
		GuiControl,, DatumInDienst, % MyFunction(data10) ; the return value of the function will be here
		GuiControl,, DatumUitDienst, % MyFunction(data11) ; the return value of the function will be here
		GuiControl,, Uitzendnummer, %data26%
		GuiControl,, Emailadres, %data27%
		if ( data25 = "Actief")
		{
			GuiControl,Choose, Status, 1
		}
		else
		{
			GuiControl,Choose, Status, 2
		}
		if ( data9 = "Vast")
		{
			GuiControl,Choose, Dienstverband, 1
			GuiControl, Hide, TextDatumUitDienst
			GuiControl, Hide, DatumUitDienst
		}
		if ( data9 = "Tijdelijk")
		{
			GuiControl, Show, TextDatumUitDienst
			GuiControl, Show, DatumUitDienst
			GuiControl,Choose, Dienstverband, 2
		}
		if ( data9 = "Uitzendkracht")
		{
			GuiControl,Choose, Dienstverband, 3
			GuiControl, Hide, TextDatumUitDienst
			GuiControl, Hide, DatumUitDienst
		}
		GuiControl, ,Huisarts , %data12%
		GuiControl, ,Huisartsnummer , %data13%
		GuiControl, ,Contact , %data14%
		GuiControl, ,Contactnummer , %data15%
		GuiControl, ,BGG , %data16%
		GuiControl, ,BGGnummer , %data17%
		GuiControl, , Maandag, % data18 := Round(data18, 2)
		GuiControl, , Dinsdag, % data19 := Round(data19, 2)
		GuiControl, ,Woensdag , % data20 := Round(data20, 2)
		GuiControl, ,Donderdag , % data21 := Round(data21, 2)
		GuiControl, ,Vrijdag , % data22 := Round(data22,2)
		GuiControl, ,Uren , % Uren := Round(data18 + data19 + data20 + data21 + data22, 2)
		}
		
	}
	
}
return
And here's the full script:

Code: Select all

#NoEnv
#Warn
#SingleInstance Force 
#KeyHistory 0
SetBatchLines, -1
SetDefaultMouseSpeed, 0
SendMode, Input

NukeSemiColon()
{
	global
	EditList := "Voornaam|Achternaam|Status|Geboortedatum|Geslacht|Adres|Postcode|Woonplaats|Toevoeging|Telefoonnummer|Mobielnummer|Emailadres|DatumInDienst|DatumUitDienst|Dienstverband|Uitzendnummer|Uren|Maandag|Dinsdag|Woensdag|Donderdag|Vrijdag|Huisarts|Huisartsnummer|Contact|Contactnummer|BGG|BGGnummer"
	Loop, Parse, EditList, % "|"
	{
		%A_LoopField% := StrReplace(%A_LoopField%, ";")
	}
	return
}

SwitchAllControls(enable)
{
	GuiControl, %enable%, Voornaam
	GuiControl, %enable%, Achternaam
	GuiControl, %enable%, Status
	GuiControl, %enable%, Geboortedatum
	GuiControl, %enable%, Geslacht
	GuiControl, %enable%, Adres
	GuiControl, %enable%, Postcode
	GuiControl, %enable%, Woonplaats
	GuiControl, %enable%, Toevoeging
	GuiControl, %enable%, Telefoonnummer
	GuiControl, %enable%, Mobielnummer
	GuiControl, %enable%, Emailadres
	GuiControl, %enable%, DatumInDienst
	GuiControl, %enable%, DatumUitDienst
	GuiControl, %enable%, Dienstverband
	GuiControl, %enable%, Uitzendnummer
	GuiControl, %enable%, Uren
	GuiControl, %enable%, Maandag
	GuiControl, %enable%, Dinsdag
	GuiControl, %enable%, Woensdag
	GuiControl, %enable%, Donderdag
	GuiControl, %enable%, Vrijdag
	GuiControl, %enable%, Huisarts
	GuiControl, %enable%, Huisartsnummer
	GuiControl, %enable%, Contact
	GuiControl, %enable%, Contactnummer
	GuiControl, %enable%, BGG
	GuiControl, %enable%, BGGnummer
	return
}

MyFunction(date,delimiter="-") ; default the delimiter to a hyphen but overridable	
{					
	MyVar := StrSplit(date,delimiter)
	If (StrLen(MyVar[1]) = 1)			; if the DAY only contains one number put a "0" in front of it.
		MyVar[1] := "0" . MyVar[1]
	If (StrLen(MyVar[2]) = 1)			; if the MONTH only contains one number put a "0" in front of it.
		MyVar[2] := "0" . MyVar[2]
		
	newDate := % myVar[3] . MyVar[2] . MyVar[1] 
	Return newDate
}
Menu, FileMenu, Add, something1
Menu, MyMenuBar, Add, &File, :FileMenu

Gui, Color, D4D0C8, F9CD63
Gui, +maximizebox
Gui, Menu, MyMenuBar
Gui, Add, Picture, x1 y8, %A_WorkingDir%\icons\user_add.png
Gui, Add, Button, x20 y3, Toevoegen
Gui, Add, Picture, x100 y8, %A_WorkingDir%\icons\user_edit.png
Gui, Add, Button, disabled x120 y3 w80 gEdit vEdit, Bewerken 
Gui, Add, ListView, +BackgroundFFFFFF x2 y52 w210 h823 AltSubmit Sort gMyListView vMyListView, Naam 
FileRead, Werknemers, werk.csv
Loop, Parse, Werknemers , `n, `r , 
{
	If ( A_Index ) = 1 ; skip headers
		Continue
	StringSplit, data, A_LoopField, `; ,%A_Space% ; remove whitspace before and after loopfield
	If ( A_LoopField ) = "" ; skip empty row
		Continue
	LV_Add(,data2 ", " data3)
}
Gui, Font, Bold
Gui, Add, Text, x2 y32 w210 h20,  Werknemers

Gui, Add, Text, x222 y32 w890 h20 , Algemene informatie
Gui, Add, Tab3, cGreen x222 y52 w890 h823 , Algemeen|Notities|Urenregistratie|Overzichten
Gui, Font
Gui, Add, Text, x232 y102 w70 h20 , Voornaam:
Gui, Add, Edit, disabled  x232 y122 w140 h20  vVoornaam , 
Gui, Add, Text, x382 y102 w80 h20 , Achternaam:
Gui, Add, Edit, disabled  x382 y122 w140 h20 vAchternaam, 
Gui, Add, Text, x232 y162 w80 h20 , Geboortedatum:
Gui, Add, DateTime, disabled x232 y182 w140 h20 ChooseNone vGeboortedatum , dd-MM-yyyy
Gui, Add, Text, x382 y162 w80 h20 , Geslacht:
Gui, Add, DropDownList, disabled x382 y182 w140 h75 vGeslacht , Mannelijk|Vrouwelijk

Gui, Add, Text, x232 y222 w80 h20 , Adres:
Gui, Add, Edit, disabled  x232 y242 w200 h20 vAdres , 

Gui, Add, Text, x451 y222 w70 h20 , Toevoeging:
Gui, Add, Edit, disabled  x451 y242 w70 h20 vToevoeging, 

Gui, Add, Text, x232 y282 w100 h20 , Postcode
Gui, Add, Edit, disabled x232 y302 w80 h20 vPostcode

Gui, Add, Text, x332 y282 w290 h20 , Woonplaats:
Gui, Add, Edit, disabled x332 y302 w290 h20 vWoonplaats

Gui, Add, Text, x232 y342 w85 h20 , Telefoonnummer:
Gui, Add, Edit, disabled  x232 y362 w140 h20 vTelefoonnummer, 

Gui, Add, Text, x382 y342 w85 h20 , Mobiel nummer:
Gui, Add, Edit, disabled  x382 y362 w140 h20 vMobielnummer, 

Gui, Add, Text, x232 y402 w85 h20 , Emailadres:
Gui, Add, Edit, disabled  x232 y422 w290 h20 vEmailadres , 

Gui, Add, Text, x642 y102 w70 h20 , Status:
Gui, Add, DropDownList, disabled x642 y122 w140 h75 vStatus , Actief||Inactief|Uit dienst

Gui, Add, Text, x792 y102 w120 h20 , Werknemersnummer:
Gui, Add, Edit, disabled  x792 y122 w120 h20 vWerknemersnummer, 

Gui, Add, Text, x642 y162 w100 h20 vTextDatumInDienst , Datum in dienst:
Gui, Add, DateTime, disabled x642 y182 w140 h20 ChooseNone vDatumInDienst , dd-MM-yyyy

Gui, Add, Text, x792 y162 w100 h20 vTextDatumUitDienst , In dienst tot:
Gui, Add, DateTime, disabled x792 y182 w120 h20 ChooseNone vDatumUitDienst , dd-MM-yyyy

Gui, Add, Text, x642 y222 w100 h20 , Dienstverband:
Gui, Add, DropDownList, disabled x642 y242 w270 h75 vDienstverband, Vast|Tijdelijk|Uitzendkracht

Gui, Add, Text, x922 y222 w150 h20 , Nummer bij uitzendbureau
Gui, Add, Edit, disabled  x922 y242 w150 h20 vUitzendnummer, 

Gui, Add, Text, x642 y282 w80 h20 , Uren per week:
Gui, Add, Edit, disabled  x642 y302 w80 h20 number vUren +Center, 

Gui, Add, Text, x722 y282 w70 h20 +Center, maandag
Gui, Add, Edit, disabled  x723 y302 w70 h20 number vMaandag +Center, 

Gui, Add, Text, x793 y282 w70 h20 +Center, dinsdag
Gui, Add, Edit, disabled  x793 y302 w70 h20 number vDinsdag +Center, 

Gui, Add, Text, x863 y282 w70 h20 +Center, woensdag
Gui, Add, Edit, disabled  x863 y302 w70 h20 vWoensdag +Center, 

Gui, Add, Text, x933 y282 w70 h20 +Center, donderdag
Gui, Add, Edit, disabled  x933 y302 w70 h20 vDonderdag +Center, 

Gui, Add, Text, x1005 y282 w70 h20 +Center, vrijdag
Gui, Add, Edit, disabled  x1003 y302 w70 h20 vVrijdag +Center, 

Gui, Add, Text, x642 y372 w100 h20 , Huisarts:
Gui, Add, Edit, disabled  x642 y392 w280 h20 vHuisarts, 

Gui, Add, Text, x932 y372 w90 h20 , Telefoonnummer:
Gui, Add, Edit, disabled  x932 y392 w140 h20 vHuisartsnummer, 

Gui, Add, Text, x642 y422 w100 h20 , Contact:
Gui, Add, Edit, disabled x642 y442 w280 h20 vContact, 

Gui, Add, Text, x932 y422 w90 h20 , Telefoonnummer:
Gui, Add, Edit, disabled  x932 y442 w140 h20 vContactnummer, 

Gui, Add, Text, x642 y472 w100 h20 , Bij geen gehoor:
Gui, Add, Edit, disabled  x642 y492 w280 h20 vBGG, 

Gui, Add, Text, x932 y472 w90 h20 , Telefoonnummer:
Gui, Add, Edit, disabled  x932 y492 w140 h20 vBGGnummer, 

Gui, Add, Button, x932 y550 w115 h25 hidden gOpslaan vOpslaan, Wijzigingen opslaan
Gui, Add, Picture, x1050 y553 hidden vAccept, %A_WorkingDir%\icons\accept.png
Gui, Add, Text, x935 y554 w115 h20 hidden vOpgeslagen , Wijzigingen opgeslagen

Gui, Font, S12 CRed Bold, Verdana
Gui, Add, Text, x642 y342 w430 h20 +Center, Waarschuwen bij noodgeval:
; Generated using SmartGUI Creator 4.0

Gui, Show, Maximize, Werknemersprogramma
Return

MyListView:
if A_GuiEvent = Normal
{
	CurrentColumn = %A_EventInfo%
	LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
	FileRead, Werknemers, werk.csv
	Loop, Parse, Werknemers , `n, `r ,%A_Space%
	{
	If ( A_Index ) = 1 ; skip column names
	{
		Continue
	}
			
	StringSplit, data, A_LoopField, `; ,%A_Space%
	SearchString = %data2%`, %data3%
	if (SearchString = RowText)
	{
		SearchString = %data2%`, %data3%
		GuiControl, enable, Bewerken
		GuiControl, ,Werknemersnummer, %data1%
		GuiControl, ,Voornaam, %data3%
		GuiControl, ,Achternaam , %data2%
		GuiControl,, GeboorteDatum, % MyFunction(data24)
		if ( data23 = "Mannelijk" )
		{
			GuiControl,Choose, Geslacht, 1
		}
		else
		{
			GuiControl,Choose, Geslacht, 2
		}
		GuiControl, ,Adres , %data4%
		GuiControl, ,Postcode, %data6%
		GuiControl, ,Woonplaats , %data5%
		GuiControl, ,Telefoonnummer , %data7%
		GuiControl, ,Mobielnummer , %data8%
		GuiControl,, DatumInDienst, % MyFunction(data10) ; the return value of the function will be here
		GuiControl,, DatumUitDienst, % MyFunction(data11) ; the return value of the function will be here
		GuiControl,, Uitzendnummer, %data26%
		GuiControl,, Emailadres, %data27%
		if ( data25 = "Actief")
		{
			GuiControl,Choose, Status, 1
		}
		else
		{
			GuiControl,Choose, Status, 2
		}
		if ( data9 = "Vast")
		{
			GuiControl,Choose, Dienstverband, 1
			GuiControl, Hide, TextDatumUitDienst
			GuiControl, Hide, DatumUitDienst
		}
		if ( data9 = "Tijdelijk")
		{
			GuiControl, Show, TextDatumUitDienst
			GuiControl, Show, DatumUitDienst
			GuiControl,Choose, Dienstverband, 2
		}
		if ( data9 = "Uitzendkracht")
		{
			GuiControl,Choose, Dienstverband, 3
			GuiControl, Hide, TextDatumUitDienst
			GuiControl, Hide, DatumUitDienst
		}
		GuiControl, ,Huisarts , %data12%
		GuiControl, ,Huisartsnummer , %data13%
		GuiControl, ,Contact , %data14%
		GuiControl, ,Contactnummer , %data15%
		GuiControl, ,BGG , %data16%
		GuiControl, ,BGGnummer , %data17%
		GuiControl, , Maandag, % data18 := Round(data18, 2)
		GuiControl, , Dinsdag, % data19 := Round(data19, 2)
		GuiControl, ,Woensdag , % data20 := Round(data20, 2)
		GuiControl, ,Donderdag , % data21 := Round(data21, 2)
		GuiControl, ,Vrijdag , % data22 := Round(data22,2)
		GuiControl, ,Uren , % Uren := Round(data18 + data19 + data20 + data21 + data22, 2)
		}
		
	}
	
}
return

Edit:
GuiControl, Disable, MyListView
GuiControl, Disable, Bewerken
GuiControl, Disable, Toevoegen
GuiControl, Show, DatumUitDienst
GuiControl, Show, Opslaan
SwitchAllControls("enable") ; turn on all controls
return

Opslaan:
gui, Submit, NoHide

NukeSemiColon()


FormatTime, GeboorteDatum,  %Geboortedatum%, dd-MM-yyyy
FormatTime, DatumInDienst,  %DatumInDienst%, dd-MM-yyyy
FormatTime, DatumUitDienst, %DatumUitDienst%, dd-MM-yyyy
IfExist TempData.csv
{
	FileDelete, TempData.csv
	Sleep, 500
	If ErrorLevel = 1
	{
		MsGbox, Er is een probleem ! Kan niet verwijderen
		Reload
	}
}

Loop ;count the number of lines in werk.csv
{
FileReadLine, CountLines, werk.csv, %A_Index%
If ErrorLevel
	{
		CountLines = % A_Index - 1 
		break
	}
}
FileRead, TempData, werk.csv
Loop, parse, TempData , `n, `r, %A_Space%
{
	SecondCounter = % A_Index
	StringSplit, TempData, A_LoopField, `;
	if TempData1 = %werknemersnummer%
	{
		;FileAppend, %werknemersnummer%;%Achternaam%;%Voornaam%;%Adres%;%Woonplaats%;%Postcode%;%Telefoonnummer%;%Mobielnummer%;%Dienstverband%;%DatumInDienst%;%DatumUitDienst%;%Huisarts%;%Huisartsnummer%;%Contact%;%Contactnummer%;%BGG%;%BGGnummer%;%Maandag%;%Dinsdag%;%Woensdag%;%Donderdag%;%Vrijdag%;%Geslacht%;%Geboortedatum%`n, TempData.csv ; 
		FileAppend, %werknemersnummer%;%Achternaam%;%Voornaam%;%Adres%;%Woonplaats%;%Postcode%;%Telefoonnummer%;%Mobielnummer%;%Dienstverband%;%DatumInDienst%;%DatumUitDienst%;%Huisarts%;%Huisartsnummer%;%Contact%;%Contactnummer%;%BGG%;%BGGnummer%;%Maandag%;%Dinsdag%;%Woensdag%;%Donderdag%;%Vrijdag%;%Geslacht%;%Geboortedatum%;%Status%;%Uitzendnummer%;%Emailadres%, TempData.csv ; 
		If SecondCounter < %Countlines%
			FileAppend, `n, TempData.csv
		
		If ErrorLevel = 1
		{
			MsGbox, Er is een probleem ! Kan niet opslaan !
			Reload
		}
		else
			continue
	}
	else
	{
		loop, 26
		{
			FileAppend, % TempData%A_Index% ";", TempData.csv
		}
		If SecondCounter < %CountLines%
		{
			FileAppend, % TempData27 "`n", TempData.csv ; add linefeed to last line
		}
		If SecondCounter = %CountLines% ; if last line reached, skip the LineFeed
		{
			FileAppend, % TempData27, TempData.csv
		}
	}
}
FileMove, werk.csv, BackupFiles/backup %A_DD%-%A_MM% %A_Hour%h%A_Min%s%A_Sec%.csv, 1
FileMove, TempData.csv, werk.csv, 0
;AutoTrim to remove leading / trailing spaces
Achternaam = %Achternaam%
Voornaam   = %Voornaam%
LV_Modify(CurrentColumn,,Achternaam ", " Voornaam)
SwitchAllControls("disable")
GuiControl, enable, MyListView
GuiControl, show, Accept
GuiControl, hide, Opslaan
GuiControl, show, Opgeslagen
GuiControl, enable, Toevoegen
Sleep, 2000
GuiControl, hide, Opgeslagen
GuiControl, hide, Accept
return

something1:
msgbox, something 1
return

GuiClose:
ExitApp
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: A_GuiEvent only reacts to mouseclick not to arrow keys/tab etc

14 Mar 2018, 08:31

BoBo wrote:OnMessage ?
Thanks, but I need a little more help...
just me
Posts: 9460
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: A_GuiEvent only reacts to mouseclick not to arrow keys/tab etc  Topic is solved

14 Mar 2018, 11:11

[b]ListView[/b] wrote:G-Label Notifications (Secondary)

Normal: The user has left-clicked a row. The variable A_EventInfo contains the focused row number.

I: Item changed. A row has changed by becoming selected/deselected, checked/unchecked, etc. If the user selects a new row, at least two such notifications are received: one for the de-selection of the previous row, and one for the selection of the new row. [v1.0.44+]: The variable A_EventInfo contains the row number. [v1.0.46.10+]: ErrorLevel contains zero or more of the following letters to indicate how the item changed: S (select) or s (de-select), and/or F (focus) or f (de-focus), and/or C (checkmark) or c (uncheckmark). For example, SF means that the row has been selected and focused. To detect whether a particular letter is present, use a parsing loop or the case-sensitive option of InStr(); for example: InStr(ErrorLevel, "S", true). Note: For compatibility with future versions, a script should not assume that "SsFfCc" are the only possible letters. Also, specifying Critical as the g-label's first line ensures that all "I" notifications are received (otherwise, some might be lost if the script cannot keep up with them).
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: A_GuiEvent only reacts to mouseclick not to arrow keys/tab etc

19 Mar 2018, 07:36

just me wrote:
[b]ListView[/b] wrote:G-Label Notifications (Secondary)

Normal: The user has left-clicked a row. The variable A_EventInfo contains the focused row number.

I: Item changed. A row has changed by becoming selected/deselected, checked/unchecked, etc. If the user selects a new row, at least two such notifications are received: one for the de-selection of the previous row, and one for the selection of the new row. [v1.0.44+]: The variable A_EventInfo contains the row number. [v1.0.46.10+]: ErrorLevel contains zero or more of the following letters to indicate how the item changed: S (select) or s (de-select), and/or F (focus) or f (de-focus), and/or C (checkmark) or c (uncheckmark). For example, SF means that the row has been selected and focused. To detect whether a particular letter is present, use a parsing loop or the case-sensitive option of InStr(); for example: InStr(ErrorLevel, "S", true). Note: For compatibility with future versions, a script should not assume that "SsFfCc" are the only possible letters. Also, specifying Critical as the g-label's first line ensures that all "I" notifications are received (otherwise, some might be lost if the script cannot keep up with them).
Thank you justme,

I tried changing if A_GuiEvent = Normal to if A_GuiEvent = I, and the gui indeed updates when using the cursor keys now,
but for some fields it shows the wrong information in the guicontrols. For instance I select say: Bill Gates, but I get the info for Mark Zuckerberg.

Edit:
I just re-read your quote, and now added critical to the g-label like so:
Gui, Add, ListView, +BackgroundFFFFFF x2 y52 w210 h823 AltSubmit Sort gMyListView Critical vMyListView, Naam

This does help, but still sometimes it cannot keep up when I very quickly press the up or down keys.

Edit 2:
Hmm. Adding Critical to the top of the script seems to fix the issue !

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: just me, KolaBorat and 136 guests