-2

I want to hear the beep without seeing 'B' as output on Notepad. How can I implement this?

if (GetAsyncKeyState('B') & 0x8000)
{
    Beep( 500, 500 );
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
JustCry
  • 40
  • 5
  • You could trigger a backspace, sort of a hack not sure if that would work. If that works for you, try this: https://stackoverflow.com/questions/5607849/how-to-simulate-a-key-press-in-c – David Ledger Nov 28 '18 at 04:48
  • I don't think SendInput and keybd_event would my solve question. My goal is to detect key press and not see output on any text document app while hearing a beep – JustCry Nov 28 '18 at 07:04
  • @dav: How would this pan out in case the `'B'` is pressed as part of a keyboard shortcut? No, I'm afraid, this is not a solution or even part of a solution. Installing a [low-level keyboard hook](https://msdn.microsoft.com/en-us/library/windows/desktop/ms644985.aspx) is a better option. – IInspectable Nov 28 '18 at 08:12

1 Answers1

2

Use a keyboard hook via SetWindowsHookEx(). When your hook callback detects the desired key stroke, you can block the key stroke so it is not passed on to subsequent hooks or the target application.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770