diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d052a0..92fb7b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,6 +21,8 @@ set(PROJECT_SOURCES
src/simulation/mouseSim.hpp
src/simulation/keyboardSim.cpp
src/simulation/keyboardSim.hpp
+ src/simulation/simulate.cpp
+ src/simulation/simulate.hpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
diff --git a/src/simulation/keyboardSim.hpp b/src/simulation/keyboardSim.hpp
index fa0ebf3..b5d1a1c 100644
--- a/src/simulation/keyboardSim.hpp
+++ b/src/simulation/keyboardSim.hpp
@@ -1,6 +1,8 @@
/**
* @file keyboardSim.hpp
* @brief Simulates keyboard input in Windows.
+ *
+ * @note Do not include this file directly. Use @link simulate.hpp @endlink instead.
*/
#pragma once
diff --git a/src/simulation/mouseSim.hpp b/src/simulation/mouseSim.hpp
index 2e4f7ec..33689f8 100644
--- a/src/simulation/mouseSim.hpp
+++ b/src/simulation/mouseSim.hpp
@@ -1,6 +1,8 @@
/**
* @file mouseSim.hpp
* @brief Simulates mouse input in Windows.
+ *
+ * @note Do not include this file directly. Use @link simulate.hpp @endlink instead.
*/
#pragma once
diff --git a/src/simulation/simulate.cpp b/src/simulation/simulate.cpp
new file mode 100644
index 0000000..0a7ac8a
--- /dev/null
+++ b/src/simulation/simulate.cpp
@@ -0,0 +1,31 @@
+#include "simulate.hpp"
+
+bool blockExternalInput()
+{
+ return BlockInput(TRUE);
+}
+
+bool unblockExternalInput()
+{
+ return BlockInput(FALSE);
+}
+
+void clearExistingInput()
+{
+ // Get the keyboard state
+ BYTE keyboardState[256];
+ GetKeyboardState(keyboardState);
+
+ // Cancel any existing input
+ // Iterates through all keys, checking if they are down, and releasing them if they are
+ for (int i = 0; i < 256; i++)
+ {
+ if (keyboardState[i] & 0x80)
+ {
+ // Release the key
+ keyUp(i);
+ }
+ // ostream_here << "0X" << std::hex << i << std::dec << "(" << i << ")"
+ // << "is" << (keyboardState[i] & 0x80 ? "down" : "up");
+ }
+}
diff --git a/src/simulation/simulate.hpp b/src/simulation/simulate.hpp
new file mode 100644
index 0000000..694240b
--- /dev/null
+++ b/src/simulation/simulate.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "keyboardSim.hpp"
+#include "mouseSim.hpp"
+
+/** This function is used to block input from external devices.
+ * It stops keyboard and mouse input events from reaching applications.
+ * It is used to prevent the user from accidentally interfering with the program.
+ *
+ * https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-blockinput
+ *
+ * @note **Emergency Exit:** CTRL + ALT + DEL
+ * @see @link unblockExternalInput()
+ */
+bool blockExternalInput();
+
+/** This function is used to unblock input from external devices.
+ * It allows keyboard and mouse input events to reach applications again.
+ *
+ * @see @link blockExternalInput()
+ */
+bool unblockExternalInput();
+
+void clearExistingInput();