View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_8_] Peter T[_8_] is offline
external usenet poster
 
Posts: 88
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
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