0

For starting VBA procedures in MS Excel by keyboard shortcuts one can assign such shortcuts following the pattern

Ctrl + [one letter]

This seems to be the only possibility provided by the makers of Excel. Even Ctrl + [a digit] does not work, as such a combination cannot be assigned using the by-default method.

I want, however, have "MS Word style shortcuts" available such as

Ctrl + [letter or digit or whatever] + [letter or digit or whatever]

because they not only give me a larger number of shortcuts but also let me assign shortcuts that help me memorize them e.g. Ctrl+d+e for "delete everything" (just an example).

Therefore I am searching for a way to create such enhanced shortcuts. I am thinking of a VBA procedure that tracks keys hit on the keyboard, and on certain combinations would start doing someting (Case a --> do x, case b --> do y, etc.).

A lazy method could be writing a procedure that reads the following two keys hit, and the procedure itself would first have to be triggered by a "by-default type" shortcut such as Ctrl + [letter]. This of course would nearly double the number of keys i have to hit to start something.

Question: Is there a way to let a VBA procedure track all keys being hit, store them e.g. into an array of e.g. four places, the way a CCTV camera records things (deleting the oldest), and pay attention for certain combinations e.g. Ctrl + [letter] + [letter], and if found do something?

Of course, such a key logger procedure should not slow down my system noticably.

Community
  • 1
  • 1

1 Answers1

1

Looks like this question has been asked before, see: Is there any event that fires when keys are pressed when editing a cell?

Looks like a lot of effort in VBA, basically using PINVOKE to get to underlying Windows functions. You may want to look at a more fully rounded development environment if you have this kind of requirement.

David Brunning
  • 575
  • 7
  • 18
  • E.g. what kind of development environment? – Christian Geiselmann Mar 09 '18 at 17:16
  • As for the link to a similar question you provided: thanks, that's a good start. Of course, as this is a complicated set of procedure, I will have to take some time to understand it and test it... but definitely helpful! – Christian Geiselmann Mar 09 '18 at 17:29
  • "E.g. what kind of development environment?" - it really depends on what you're doing, but using something like Visual Studio to build a WPF project, for example, includes events for PreviewKeyDown and is possibly better suited to build a complex UI. – David Brunning Mar 12 '18 at 12:44