NightmareXIV / AntiAfkKick

An application, Dalamud and ACT plugin for preventing being auto-kicked from FFXIV due to inactivity.
GNU Affero General Public License v3.0
109 stars 21 forks source link

Question - NextKeyPress = 0 why have it? (update line was commented out) #7

Closed patrat46 closed 2 years ago

patrat46 commented 2 years ago

In AntiAfkKick/AntiAfkKick.cs in the current revision (16 days old) https://github.com/Eternita-S/AntiAfkKick/blob/44e3b75e2d31c94384b555492488fecabbc82816/AntiAfkKick/AntiAfkKick.cs

Below is the code referencing the tick and the next key press. The way it is writting Next Key Press is never updated from 0 This means that the if (Native.GetTickCount64() > NextKeyPress) will return true 100% of the time.

The if statement is then not needed, the variable is also not used, and the rest is determined by the thread being inactive for more than 1 minute.

Sorry to bug you, I'm mostly just curious.


static ulong NextKeyPress = 0;

  new Thread((ThreadStart)delegate
                {
                    while (true)
                    {
                        Thread.Sleep(10000);
                        Console.WriteLine($"Cycle begins {Native.GetTickCount64()}");
                        try
                        {
                            if (Native.GetTickCount64() > NextKeyPress) {
                                foreach (var handle in Native.GetGameWindows())
                                {
                                    if(Native.GetForegroundWindow() != handle || Native.IdleTimeFinder.GetIdleTime() > 60 * 1000)
                                    {
                                        Console.WriteLine(Native.GetTickCount64() + ": Sending keypress to FFXIV window " + handle.ToString());
                                        Native.Keypress.SendKeycode(handle, Native.Keypress.LControlKey);
                                    }
                                }
                                **//NextKeyPress = Native.GetTickCount64() + 2 * 60 * 1000;**
                            }
                        }
                        catch (Exception) { }
                    }

The code is essentially the same this way right?


 new Thread((ThreadStart)delegate
                {
                    while (true)
                    {
                        Thread.Sleep(10000);
                        Console.WriteLine($"Cycle begins {Native.GetTickCount64()}");
                        try
                        {
                         foreach (var handle in Native.GetGameWindows())
                            {
                                 if(Native.GetForegroundWindow() != handle || Native.IdleTimeFinder.GetIdleTime() > 60 * 1000)
                                 {
                                     Console.WriteLine(Native.GetTickCount64() + ": Sending keypress to FFXIV window " + handle.ToString());
                                     Native.Keypress.SendKeycode(handle, Native.Keypress.LControlKey);
                                 }
                            }
                        }
                        catch (Exception) { }
                    }
Limiana commented 2 years ago

Hello! And oops, I commented that line out for debugging and never put it back. I will fix it now, but it's nothing critical, so there is no big need to download new release. Thank you for report!

Aethusx commented 2 years ago

confirmed, without this line it will send keypress every 10s.

Limiana commented 2 years ago

Binary is updated now. Updating is not mandatory as there are no negative effects from sending keypress that often, other than very negligible amount of extra cpu load.