Steal F11 keystroke away from Excel

Started by gibberish, May 28, 2018, 08:23:35 AM

Previous topic - Next topic

gibberish

Switching back and forth between my IDE debugger and Excel, I am forever hitting F11 ("next step" in VSCode debugger) when Excel has the focus - and Excel creates a new chart (F11).

Is there any way to disable or reassign F11 in Excel? I am ready to defenestrate Excel through the MS Windows.

I tried creating a forever-looping script in WinBatch using WaitForKey that would watch for and nullify the keystroke, but it still gets passed to Excel at the same time and creates that accursed chart tab. Any thoughts?

gibberish

Got the VBA answer on StackOverflow https://stackoverflow.com/questions/50569095/excel-disable-f11-keystroke/50569495#50569495.

But still wondering about the WinBatch part of the question, re preventing Excel from receiving the keystroke in the first place. Is there a way to do that?

stanl

I posted a reply, then yanked it - basically it was a simple conversion of the VBA code to WB. But it seems you are using Visual Studio so now I'm confused as to how WB fits into your post.

td

I guess this is one of the reasons why people have 2 and 3 monitor systems.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

gibberish

Hi Stan, thanks for answering. I asked the question because my initial go-to for this problem was WinBatch, thinking it might be able to intercept the keyboard buffer before another program. (Perhaps I am over-confident, but I was pretty sure WinBatch could do this, especially remembering previous code examples from snowsnowsnow, guido, tonyd, yourself - but after trying it, I realized this was a question for the mavens.)

Although I had a specific use case for this (i.e. Excel and F11), I've run into this question before and am still keen to find an answer. I recall years ago that there was a script posted (trap keys, or some such) that intercepted keystrokes, but it was likely taken down for obvious reasons. Still, reading the keyboard buffer has legitimate purposes, such as this. I am not low-level enough to understand how to use BinaryPeek8/BinaryPoke8, etc. or to author the code written below. In my routines vault, I have a GetKeyboardState() function (below) that I found years ago in the tech database, but am not sure how to use it in this case.


#DefineFunction udfGetKeyboardState(KbdBuf,KbdBufSize)
   sDLLName = StrCat(DirWindows(1), "user32.dll")
   DLLCall(sDLLName, long:"GetKeyboardState", lpbinary:KbdBuf)
   BinaryEodSet(KbdBuf, KbdBufSize)
   return KbdBuf
#EndFunction ;udfGetKeyboardState



Having received an answer that resolved the narrow case of Excel-only, I still had this question regarding WinBatch. Pretty sure I'm not the first person to have this question and doubt that I will be the last - and I know I will encounter it again myself at some point. So I was still wondering how to use WinBatch to solve this type of question even after I found a solution for my specific Excel question.

Tony, I didn't understand your comment - I am using two monitors and that is how the problem arose. Excel on one monitor, my IDE on the other, and hitting F11 when I am focused on the wrong monitor.