do an *action* when any key or mouse movement is detected

6diegodiego9

Board Regular
Joined
Jan 9, 2018
Messages
80
Office Version
  1. 2016
Platform
  1. Windows
Is it possible in VBA to detect a system wide key or mouse movement?

I need to trigger an *action* when any key or mouse movement is detected system (Windows) wide
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Is it possible in VBA to detect a system wide key or mouse movement?

I need to trigger an *action* when any key or mouse movement is detected system (Windows) wide

It is possible using system wide hooks (Do a search for WH_KEYBOARD_LL and WH_MOUSE_LL) but it would be very heavy for your vba to sustain plus you will need rigurous error handling.... You could perhaps run the hook code from a seperate excel instance created on the fly in order to minimize the above issues.

Another possibility is to use a windows timer (SetTimer) and continiously monitor the keyboard state (GetAsyncKeyState, GetKeyboardState ...) and mouse actions (GetAsyncKeyState,GetCursorPos...)

Do a search for all those APIs and you will find some examples.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top