Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Handle keyboard events

10 views
Skip to first unread message

Tatsujin

unread,
Dec 30, 2020, 3:36:53 AM12/30/20
to
How can I detect when a user presses Ctrl+Alt+G (or any similar key combination) while any worksheet is active? Thanks

Peter T

unread,
Dec 31, 2020, 9:55:16 AM12/31/20
to
"Tatsujin" <tatsuj...@gmail.com> 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/office/vba/api/excel.application.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/microsoft.public.excel.programming/search?q=%22peter%20t%22%20GetAsyncKeyState

Peter T


0 new messages