View Single Post
  #2   Report Post  
Old December 31st 20, 03:56 PM posted to microsoft.public.excel.programming
Peter T[_8_] Peter T[_8_] is offline
external usenet poster
First recorded activity by ExcelBanter: Jul 2019
Posts: 86
Default 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

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

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!

Peter T