Recent

Author Topic: Capture key in form with main menu open  (Read 3231 times)

joviali

  • New Member
  • *
  • Posts: 15
Capture key in form with main menu open
« on: December 10, 2017, 03:22:46 pm »

I have a form with a main menu assigned.
How do I capture the key that I have pressed on the form when the main menu is open?

When the menu is closed (collected) I capture the keys without problems in the onkeypress event.

I tried with actionList, but it does not work either.

tks.

Thaddy

  • Hero Member
  • *****
  • Posts: 14211
  • Probably until I exterminate Putin.
Re: Capture key in form with main menu open
« Reply #1 on: December 10, 2017, 03:28:53 pm »
Since the menu has focus, including the keyboard focus, this is essentially not possible. (Unless you write some custom hacks that nobody understands)
Specialize a type, not a var.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Capture key in form with main menu open
« Reply #2 on: December 10, 2017, 05:57:20 pm »
Use a system hotkey ... or change the program structure...  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: Capture key in form with main menu open
« Reply #3 on: December 11, 2017, 11:10:35 pm »
Tell the goal, maybe it can be solved in other ways. For example, you want to know which menu items were selected during use, or just which item was executed.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Capture key in form with main menu open
« Reply #4 on: December 11, 2017, 11:40:13 pm »
if you really want it bad enough you can hook the window procedure..
The only true wisdom is knowing you know nothing

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Capture key in form with main menu open
« Reply #5 on: December 12, 2017, 02:54:31 am »
Quote
if you really want it bad enough you can hook the window procedure..
Yeah.. there are some users out there with an addiction to a secure system who really don't like that at all...
All the other users probably won't recognize this...  :)

// my bad... had a global hook in mind...  :D
« Last Edit: December 12, 2017, 06:30:06 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

joviali

  • New Member
  • *
  • Posts: 15
Re: Capture key in form with main menu open
« Reply #6 on: December 16, 2017, 09:20:04 pm »
The problem I have is the following I have a keyboard which tempts a physical key where you could change position.

Every time I change the key it sends me the following:
Position 0 = K 0
Position 1 = k 1
Position 2 = K 2



In the main form I capture those key combinations to know in what position the physical key is.



As when I activate the main menu if the position of the key is changed, I do not know.

Thanks for having answered me. :)

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: Capture key in form with main menu open
« Reply #7 on: December 17, 2017, 12:08:03 am »
The problem I have is the following I have a keyboard which tempts a physical key where you could change position.
...
Does the change key message come in all the processes? In other words, what happens if another process is currently active?
Is there a function to poll the current state of a key?

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Capture key in form with main menu open
« Reply #8 on: December 17, 2017, 01:18:51 am »
If you don't mind getting down to the Windows API level you can use the
SetWindowsHookEx function where you can monitor all keyboard events going to
your specified thread or all threads for you app.

 of course this I doubt makes it cross platform compatible, just for windows.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018