fix: add copy paste fallback detection

This commit is contained in:
TheMrGong 2021-04-30 23:04:52 -04:00
parent 8080129d58
commit 65a4f4540c

View File

@ -201,12 +201,17 @@ The following helper methods are available:
internal static bool IsUserCopyPasting() internal static bool IsUserCopyPasting()
{ {
return inputsWithinThreshold > inputThreshold;
return (InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl)) return (InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl))
&& InputManager.GetKeyDown(KeyCode.V); && InputManager.GetKeyDown(KeyCode.V);
} }
public void UpdateConsole() public void UpdateConsole()
{ {
if (inputsWithinThreshold > 0 && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - lastInputChange >= inputSpamThresholdMs * 2)
{
inputsWithinThreshold = 0;
}
if (s_copyPasteBuffer != null) if (s_copyPasteBuffer != null)
{ {
if (!IsUserCopyPasting()) if (!IsUserCopyPasting())
@ -290,8 +295,26 @@ The following helper methods are available:
internal static string s_copyPasteBuffer; internal static string s_copyPasteBuffer;
internal static long lastInputChange;
internal static int inputsWithinThreshold;
internal static readonly long inputSpamThresholdMs = 5;
internal static readonly long inputThreshold = 1;
public void OnInputChanged(string newText, bool forceUpdate = false) public void OnInputChanged(string newText, bool forceUpdate = false)
{ {
var timeSinceLastInput = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - lastInputChange;
lastInputChange = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
if (timeSinceLastInput < lastInputChange)
{
inputsWithinThreshold++;
}
else
{
inputsWithinThreshold = 0;
}
if (IsUserCopyPasting()) if (IsUserCopyPasting())
{ {
//Console.WriteLine("Copy+Paste detected!"); //Console.WriteLine("Copy+Paste detected!");