JohnFromAustralia Posted September 23, 2018 Posted September 23, 2018 Hello there, I am looking to prevent mouse and keyboard movement while running a macro (else my macro will easily fail). I use the C# nuget package. I notice (or cannot find) that there is no BlockInputs method to use with the c# wrappers. Am I blind or has that just not been implemented? Pending that, I also attempted the following stackoverflow post. To no avail.https://stackoverflow.com/questions/20841501/blockinput-method-doesnt-work-on-windows-7 Does anyone have any idea how I can prevent mouse and keyboard input while a macro is running? Thank you kindly for any ideas or help Best Regards John
Earthshine Posted September 23, 2018 Posted September 23, 2018 Why not do it in c#. I don’t believe those methods are available in the wrapper https://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C My resources are limited. You must ask the right questions
JohnFromAustralia Posted September 24, 2018 Author Posted September 24, 2018 I would do it in c#, but it's proven difficult....that link looks very promising....will give it a try and hopefully I can get it working... Would be nice if it was in the wrapper tho I would have thought it'd be a pretty common requirement...no matter.. Will report back when I find something that works... Thank you heaps for your tip John
JohnFromAustralia Posted September 25, 2018 Author Posted September 25, 2018 Just an update...I've had no success with that...looked promising, but nothing seems to get supressed...talk about rabbit warrens....wish I had an answer to supply....will return with one when I get there...
JohnFromAustralia Posted October 3, 2018 Author Posted October 3, 2018 Hi again, For anyone who stumbles accross this....I know realise why my C# code wasn't working to blockinputs....its because you need to run as administrator (elevated previleges)... Here is some little bit of messy code / test unit that works when running as administrator; expandcollapse popupusing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Runtime.InteropServices; using System.Threading; namespace SystemBetPro.Scrape { public partial class AllTests { //https://stackoverflow.com/questions/20841501/blockinput-method-doesnt-work-on-windows-7 [DllImport("user32.dll", SetLastError = true)] public static extern bool BlockInput(bool fBlockIt); //Example Usage public static void BlockInputForInterval(int spanAsMilliseconds) { try { BlockInput(true); Thread.Sleep(spanAsMilliseconds); } finally { BlockInput(false); } } [TestMethod] public void BlockInputsSupressInputsTest() { BlockInputForInterval(5000); } }//endclass } //endnamespace Earthshine 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now