ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Handle keyboard events (https://www.excelbanter.com/excel-programming/455019-handle-keyboard-events.html)

Tatsujin December 30th 20 09:36 AM

Handle keyboard events
 
How can I detect when a user presses Ctrl+Alt+G (or any similar key combination) while any worksheet is active? Thanks

Peter T[_8_] December 31st 20 03:56 PM

Handle keyboard events
 
"Tatsujin" wrote in message
How can I detect when a user presses Ctrl+Alt+G (or any similar key
combination) while any worksheet is active? Thanks


If you only want to trap one or perhaps a handful of key combinations use
Application.OnKey

https://docs.microsoft.com/en-us/off...lication.onkey

Sub CtrlAltG(bInit As Boolean)
Application.OnKey "^%g", IIf(bInit, "TestCtrlAltG", "")
End Sub

Sub TestCtrlAltG()
MsgBox "TestCtrlAltG"
End Sub

Don't forget to clear any OnKeys when done, for example in the workoks close
event

For something more general purpose look into use of the GetAsyncKeyState
API, though Alt strokes probably won't pass through the sheet, so to speak.
Some examples from long ago!

https://groups.google.com/g/microsof...tAsyncKeyState

Peter T




All times are GMT +1. The time now is 03:51 PM.

Powered by vBulletin® Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
ExcelBanter.com