Author Topic: Steal F11 keystroke away from Excel  (Read 112 times)

gibberish

  • Newbie
  • *
  • Posts: 7
Steal F11 keystroke away from Excel
« on: May 28, 2018, 08:23:35 am »
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

  • Newbie
  • *
  • Posts: 7
Re: Steal F11 keystroke away from Excel
« Reply #1 on: May 28, 2018, 08:42:30 am »
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

  • Pundit
  • *****
  • Posts: 750
Re: Steal F11 keystroke away from Excel
« Reply #2 on: May 29, 2018, 03:35:47 am »
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

  • Tech Support
  • *****
  • Posts: 2465
    • WinBatch
Re: Steal F11 keystroke away from Excel
« Reply #3 on: May 29, 2018, 01:34:48 pm »
I guess this is one of the reasons why people have 2 and 3 monitor systems.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


gibberish

  • Newbie
  • *
  • Posts: 7
Re: Steal F11 keystroke away from Excel
« Reply #4 on: June 05, 2018, 08:23:08 am »
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.

Code: [Select]
#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.