-
Mar 26th, 2020, 01:37 PM
#1
Thread Starter
New Member
Excel VBA mouse jiggler with Windows API calls not working on Win10
My corporate environment imposes a 10 min inactivity timeout which wastes my time as I run both a production and a test computer. A few years ago I wrote a simple Excel VBA macro to jiggle the mouse one pixel every 5 min which worked great, but stopped working when I was moved from Windows 7 to Windows 10.
I'm now running Excel 2013 32 bit on Win 10 Pro 64 bit.
I'm using Windows API calls in my macro to simulate mouse and keyboard events, but Windows still locks my screen after 10 min. In addition to mouse moves, I've added mouse clicks and keyboard presses to my code.
I even have one version that does all of the following in a loop: visibly drags the current Excel window around the desktop, visibly toggles the caps lock key (my Dell keyboard has a lighted caps lock key that goes on and off), and visibly opens the Windows Start menu on my computer by placing the cursor on the Windows icon and sending a click. But Windows still locks my screen while this is running due to "inactivity".
The windows api calls I am using are:
Private Declare PtrSafe Function GetCursorPos Lib "user32.dll" (Point As POINTAPI) As Long
Private Declare PtrSafe Function SetCursorPos Lib "user32.dll" (ByVal x As Integer, ByVal y As Integer) As Long
Private Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare PtrSafe Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As LongPtr, ByVal dwExtraInfo As LongPtr)
Private Declare PtrSafe Function GetKeyboardState Lib "user32.dll" (ByVal lpKeyState As LongPtr) As Boolean
Private Declare PtrSafe Function SetKeyboardState Lib "user32.dll" (ByVal lpKeyState As LongPtr) As Boolean
Declare PtrSafe Function SetWindowPos Lib "user32" ( _
ByVal hwnd As LongPtr, _
ByVal hWndInsertAfter As LongPtr, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Declare PtrSafe Function FindWindow Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As LongPtr
Private Sub SingleClick()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Private Sub ToggleCapsLock(enabled As Boolean)
'Poll current keyboard state.
GetKeyboardState (VarPtr(keystate(0)))
If (Not keystate(VK_CAPSLOCK) And enabled) Or (keystate(VK_CAPSLOCK) And Not enabled) Then
'Send a keydown
keybd_event VK_CAPSLOCK, CapsLockScanCode, KEYEVENTF_EXTENDEDKEY, 0&
'Send a keyup
keybd_event VK_CAPSLOCK, CapsLockScanCode, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0&
End If
End Sub
-
Mar 26th, 2020, 03:37 PM
#2
Re: Excel VBA mouse jiggler with Windows API calls not working on Win10
Do you have the ability to run Windows Media Player on these computers? If yes, another solution that might work and would be worth testing is to play a short video, with the Repeat function activated, and the sound for Windows Media Player muted, to see if your screen still locks after 10 minutes. If it does lock, then it is possible that your company's IT staff were previously employed by Dilbert's company.
This works on my work computers. I use a music video (does not have to have actual video motion) that I downloaded from YouTube.
-
Mar 27th, 2020, 01:48 PM
#3
Thread Starter
New Member
Re: Excel VBA mouse jiggler with Windows API calls not working on Win10
jdc2000,
I have tried the Windows Media player looping video trick and it doesn't work in my corporate environment. I believe there's some sort of a Windows group policy that can be set to prevent that, does this system administrators have learned about this trick.
I don't have admin rights on my machine. I cannot run any executable that isn't pre-approved without it getting quarantined. They have Windows powershell and batch file programming locked down. At this point, the only thing I can think of he's to write VBA code, because I do need to do that for my job.
I just don't understand why if I physically jiggle the mouse, Windows 10 interprets this as activity, but if I use the windows API calls in vba, Windows 10 doesn't. Again, this worked under Windows 7.
-
Mar 27th, 2020, 01:52 PM
#4
Thread Starter
New Member
Re: Excel VBA mouse jiggler with Windows API calls not working on Win10
The Windows Media player trick does it work in my corporate environment. Apparently there's some sort of ssecurity policy that the systems administrator can set to frustrate trick.
I just don't understand why, if I physically jiggle my mouse, Windows 10 interprets this is activity. But if I use the windows API calls, Windows 10 doesn't. Again, it worked under Windows 7.
-
Mar 27th, 2020, 05:16 PM
#5
Re: Excel VBA mouse jiggler with Windows API calls not working on Win10
My guess would be that your Dogbert IT staff have something set so the VBA macro does not work. Windows 10 is also more locked down that Windows 7 and has more Group Policy items available.
At this point, I would suggest that, if you have a personnel computer available with Windows 10 and Office, that you try your macro on that to see if it works. Or, maybe someone else on these forums could try your code. I use macros all the time, so I don't want other macro running that could cause issues. The Windows Media Player trick does work for me though.
-
Mar 27th, 2020, 08:47 PM
#6
Re: Excel VBA mouse jiggler with Windows API calls not working on Win10
Just get a wireless mouse and put it in your pocket.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Mar 28th, 2020, 08:33 AM
#7
Thread Starter
New Member
Re: Excel VBA mouse jiggler with Windows API calls not working on Win10
That's a cool new idea I haven't heard of before, but the windows registry logs identifying info on each new USB device plugged in. My company has very strict policy of not allowing unapproved USB devices. They don't want malware introduced via unapproved devices or employees loading sensitive data onto a flash drive and taking it out of the company.
-
Mar 28th, 2020, 11:52 AM
#8
Re: Excel VBA mouse jiggler with Windows API calls not working on Win10
My company also logs USB device insertions and reports most devices and warns the user if a thumbdrive, CD/DVD or external hardrive is added, but it doesn't complain to the user about HID devices, like wireless Keyboard/Mouse insertions, although they may be logged, I don't know.
Wireless keyboards and mice are used in a lot of the labs, with the exception of any labs that do classified work, in which case no wireless technology, i.e. fitness trackers, cellphones, any bluetooth capable devices, etc. are allowed, so no wireless keyboard or mice in there.
I just got the idea because sometimes I've had to move between various places and have slipped my mouse into my pocket to make carrying my running labtop and other things easier. The first time I did it, I wasn't really thinking at first and I noticed that my mouse was moving around the screen while I was walking and it took me a second or two to realize why.
I now usually remember to turn the mouse off before I put it in my pocket when I have to move between rooms.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Apr 8th, 2020, 12:34 PM
#9
Re: Excel VBA mouse jiggler with Windows API calls not working on Win10
Last edited by jdc2000; Apr 8th, 2020 at 12:40 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|