From fb9f4a38752ef18226364daa2d9dc49a2ced26b1 Mon Sep 17 00:00:00 2001 From: PhatDave Date: Wed, 27 Oct 2021 15:51:08 +0200 Subject: [PATCH] Added some form of sorting --- Echo.ahk | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Echo.ahk b/Echo.ahk index 2484e51..4f25831 100644 --- a/Echo.ahk +++ b/Echo.ahk @@ -15,8 +15,8 @@ global enabledWindows := Array() enabledWindows.Push(Array()) enabledWindows.Push(Array()) -global keyLog := {} -global whitelistKeys := {} +global keyLog := Array() +global whitelistKeys := Array() OnKeyDown(InputHook, VK, SC) { key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC)) @@ -41,6 +41,39 @@ OnKeyUp(InputHook, VK, SC) { } } +; Not really mine at all +SortArray(Array, Order="A") { + ;Order A: Ascending, D: Descending, R: Reverse + MaxIndex := ObjMaxIndex(Array) + If (Order = "R") { + count := 0 + Loop, % MaxIndex + ObjInsert(Array, ObjRemove(Array, MaxIndex - count++)) + Return + } + Partitions := "|" ObjMinIndex(Array) "," MaxIndex + Loop { + comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, "|", False, 0)+1), ",") + spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1) + if (Order = "A") { + Loop, % epos - spos { + if (Array[pivot] > Array[A_Index+spos]) + ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos)) + } + } else { + Loop, % epos - spos { + if (Array[pivot] < Array[A_Index+spos]) + ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos)) + } + } + Partitions := SubStr(Partitions, 1, InStr(Partitions, "|", False, 0)-1) + if (pivot - spos) > 1 ;if more than one elements + Partitions .= "|" spos "," pivot-1 ;the left partition + if (epos - pivot) > 1 ;if more than one elements + Partitions .= "|" pivot+1 "," epos ;the right partition + } Until !Partitions +} + WinGetAll() { PIDs := Array() winTitles := Array() @@ -142,6 +175,7 @@ KeyLogToString() { WhitelistButtonUI() { Gui, Destroy + SortArray(keyLog) string := KeyLogToString() Gui, Add, ListBox, Multi w500 vKeyLogUI r10, %string% Gui, Add, Button, Default, Save @@ -154,7 +188,7 @@ WhitelistButtonUI() { WhitelistKeys(string) { for k, v in StrSplit(string, "|") { - whitelistKeys[v] := true + whitelistKeys.Insert(v) } }