Recent

Author Topic: Ability to use the Win key to assign a specific IDE function  (Read 2705 times)

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Ability to use the Win key to assign a specific IDE function
« on: October 05, 2024, 04:20:04 pm »
I had been working on ThinkPad laptops for a very long time, and they had a great keyboard. One of the advantages was that the up arrow key had keys with the codes VK_BROWSER_BACK and VK_BROWSER_FORWARD on either side (see the attachment). I had assigned functions to these keys that allowed me to move around the code editor tabs and jump between code editor windows (alone keys to switch between tabs in a given editor window, with the Ctrl key to switch between editor windows). This made working very convenient.

I recently switched to a stationary PC and am currently working on a full-size keyboard that does not have these two keys. So I lost the ability to conveniently move between tabs and windows. For now, I have set other shortcuts for these functions (Ctrl+Tab and Shift+Ctrl+Tab to change tabs and Ctrl+` to change the editor window), but they are not convenient for me.

Up until now I had my shortcuts set up so that I could either use my right hand to use these functions (e.g. BrowserNext to change tabs), or both (e.g. Ctrl+BrowserNext to change windows). Now I have to use only my left hand (e.g. Ctrl+Tab), which is a real pain for me because I have to fight muscle memory.

Ideally, I could use the arrow keys combined with one of the special keys on the left side of the keyboard. The available keys are: Ctrl, Shift, Alt, and Win. I already use the first three keys for many code editor functions, so I no longer have any sensible shortcuts that would be unassigned — the Win key remains.

If it were possible to use the Win key for IDE function shortcuts, I would use it — Win+Left/Right to move between tabs in the active code editor window and, for example, Ctrl+Win+Left/Right to move between code editor windows. That would be very convenient for me. Well, it would be, because the IDE does not allow the use of the Win key in IDE function shortcuts.

Why? Why can't you use this key?
« Last Edit: October 05, 2024, 04:23:25 pm by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Ability to use the Win key to assign a specific IDE function
« Reply #1 on: October 05, 2024, 05:02:10 pm »
I know the feeling... Could us a few extra keys myself.

Ignoring issue with cross platform....

Have you tried? In your own app? To react to those keys and suppress it from going to Windows? IIRC it can be suppressed (in most cases) if another key is pressed with it (while it is hold down). But if you press and depress it, without pressing another key (maybe changed your mind) then the start up menu pops up. It may not bother you, but it's not a user experience for everyone.

Considering that the "Alt + Ctrl" keycodes already cause trouble, because they can't be distinguished from AltGr and that is needed to type various common keys on non English keyboards...  The Win key is going to call for even more trouble.



marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11942
  • FPC developer.
Re: Ability to use the Win key to assign a specific IDE function
« Reply #2 on: October 05, 2024, 05:17:51 pm »
IIRC those keys are reserved for system level usage on Windows, and not passed onto applications.

440bx

  • Hero Member
  • *****
  • Posts: 4736
Re: Ability to use the Win key to assign a specific IDE function
« Reply #3 on: October 05, 2024, 05:51:32 pm »
Take what follows with a grain of salt because I've never tried using the Winkey in my code.

It _seems_ that it should be possible for user code to use the Winkey.  I say that because some MS Office apps make use of it.  For instance, in Onenote win-shift-s takes a screenshot (per Wikipedia.)

It should not take much work to write a little test program to see if an app/window gets a WM_CHAR (or some other message) upon the winkey being pressed/depressed.

Of course, using the winkey is a bit problematic because MS seems to have reserved that key for itself.  Therefore any use you make of it could easily conflict with ways it's already used or will be used in the future (by MS.)

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

440bx

  • Hero Member
  • *****
  • Posts: 4736
Re: Ability to use the Win key to assign a specific IDE function
« Reply #4 on: October 05, 2024, 06:04:54 pm »
Just tried it...

for the winkey an app gets a WM_KEYDOWN followed by a WM_KEYUP. 

Windows reacts to the WM_KEYUP.  That's when it chooses to show the start menu. 

One possible useful characteristic is that if the user presses shift, alt, or ctrl _before_ pressing the winkey then Windows does not do anything.  IOW, if you required the other keys to be pressed first then you could assign some functions to combinations that include the winkey.

The other possibility would be to "eat" the winkey in all cases thereby preventing windows from seeing/using it.  IOW, usurping the winkey for your program. :)

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Ability to use the Win key to assign a specific IDE function
« Reply #5 on: October 05, 2024, 06:08:37 pm »
Yes you get the keydown/up.
You can even set the "key" to zero, and in some (but not all cases) that works.

On the other hand, Windows itself adds more and more shortcuts to that key. So conflicts are more and more likely.

440bx

  • Hero Member
  • *****
  • Posts: 4736
Re: Ability to use the Win key to assign a specific IDE function
« Reply #6 on: October 05, 2024, 06:17:14 pm »
On the other hand, Windows itself adds more and more shortcuts to that key. So conflicts are more and more likely.
Yes, that's the real problem. 

I cannot think of a useful/reasonable way of using the winkey that is not, at least potentially, undesirably invasive.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16184
  • Censorship about opinions does not belong here.
Re: Ability to use the Win key to assign a specific IDE function
« Reply #7 on: October 05, 2024, 06:36:31 pm »
The constants are:
VK_LWIN and VK_RWIN and they are available to programmers.
I am not sure these two are defined in the current Windows unit (maybe use jwaWindows instead?).
I have used them elsewhere, but not in Pascal, probably C++.
If they are defined correctly, there should not be any difference between these two and ctrl, alt and family.

If using them is a good idea is another story, as mentioned.
« Last Edit: October 05, 2024, 06:42:43 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Ability to use the Win key to assign a specific IDE function
« Reply #8 on: October 05, 2024, 06:49:02 pm »
But if you press and depress it, without pressing another key (maybe changed your mind) then the start up menu pops up. It may not bother you, but it's not a user experience for everyone.

Even now, exactly the same kind of "problem" exists with the left Alt key — pressing and releasing it focuses the first item on the main menu. Does anyone complain that this is the default behavior of the system? Of course not.

The real bananas will be when the user tries to set the Alt+Tab shortcut (which is currently allowed). The IDE will allow you to set such a shortcut without a problem, but it will never work properly. And the same with the Ctrl+Alt+Del shortcut. But this is just a fun fact, not a problem at all.

I cannot think of a useful/reasonable way of using the winkey that is not, at least potentially, undesirably invasive.

I have a lot of ideas for its use, including the ones I wrote about earlier. Especially since if you execute a shortcut with the Win key (Win+something) and it is not a shortcut understood by the system (e.g. Win+L to switch users), it simply ignores it and does not open the Start menu.

And as I wrote earlier, if someone wants to use a given shortcut, but it may conflict with system functions, they will do so knowing the consequences. I know that many shortcuts with the Win key are already reserved by the system, so I would use those that will not conflict with it. Currently, I have no freedom in this matter.
« Last Edit: October 05, 2024, 06:57:40 pm by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

440bx

  • Hero Member
  • *****
  • Posts: 4736
Re: Ability to use the Win key to assign a specific IDE function
« Reply #9 on: October 05, 2024, 06:56:43 pm »
I know that many shortcuts with the Win key are already reserved by the system, so I would use those that will not conflict with it. Currently, I have no freedom in this matter.
The problems will occur when MS decides to use some combination(s) you decided to use too.  That is not a recipe for a desirable situation.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Ability to use the Win key to assign a specific IDE function
« Reply #10 on: October 05, 2024, 07:01:40 pm »
The problems will occur when MS decides to use some combination(s) you decided to use too.

I love being treated like a retarded child, incapable of solving absolutely any problem. And I especially love it when someone knows better than me what is good for me and tries to forbid me from doing anything that might cause a problem.

Even if Microsoft adds one of the system shortcuts that I would use, for God's sake, there is nothing stopping me from changing this shortcut in the IDE settings. However, as long as a given shortcut is free and the system does not use it for anything, I would like to be able to use it to improve my working conditions with the IDE.
« Last Edit: October 05, 2024, 07:06:08 pm by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

440bx

  • Hero Member
  • *****
  • Posts: 4736
Re: Ability to use the Win key to assign a specific IDE function
« Reply #11 on: October 05, 2024, 07:11:53 pm »
I love being treated like a retarded child, incapable of solving absolutely any problem. I especially love it when someone knows better than me what is good for me and tries to forbid me from doing something that might cause a problem.
I got a good laugh out of that.  :D


Even if Microsoft adds one of the system shortcuts that I would use to the set of shortcuts, for God's sake, there is nothing stopping me from changing this shortcut in the IDE settings.
That statement implies the program is strictly for your personal use because while you may not mind having to get accustomed to new shortcuts, users of your program may not feel the same way. 

If the program is strictly for your personal use, that's a detail you could have mentioned when it was pointed out that your choices had the potential to conflict with those - eventually - made by MS.

Anyway... yes, you can use the winkey however you like,  Be my guest.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Ability to use the Win key to assign a specific IDE function
« Reply #12 on: October 05, 2024, 07:31:12 pm »
I just remind not to be a hypocrite on this topic.

Already now, Lazarus not only allows you to set shortcuts that are reserved by the system and will never work as intended by the user (e.g. Alt+Tab or Ctrl+Alt+Del), but it also does not inform the user about potential problems while setting these shortcuts. So I don't see any reason to prohibit the use of the Win key, since the user can already set reserved shortcuts that will not meet expectations. What's more, you can easily assign individual letter and number keys to specific IDE functions, and thus be unable to write code. Does anyone do such things? Of course not.

So if Lazarus can correctly recognize the Win key and respond to shortcuts composed with this key (and it seems like it can, since other applications can do it), it would be worth adding such an option.
« Last Edit: October 05, 2024, 07:34:55 pm by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

Thaddy

  • Hero Member
  • *****
  • Posts: 16184
  • Censorship about opinions does not belong here.
Re: Ability to use the Win key to assign a specific IDE function
« Reply #13 on: October 05, 2024, 07:46:31 pm »
So if Lazarus can correctly recognize the Win key and respond to shortcuts composed with this key (and it seems like it can, since other applications can do it)
That doesn't require anything, just the constants.
Still, if it is sane is another story.

Lazarus apps will listen to VK_LWIN and VK_RWIN. I already explained that.
If I smell bad code it usually is bad code and that includes my own code.

440bx

  • Hero Member
  • *****
  • Posts: 4736
Re: Ability to use the Win key to assign a specific IDE function
« Reply #14 on: October 05, 2024, 07:57:55 pm »
Already now, Lazarus not only allows you to set shortcuts that are reserved by the system and will never work as intended by the user (e.g. Alt+Tab or Ctrl+Alt+Del), but it also does not inform the user about potential problems while setting these shortcuts.
You're going to use that as a rationale to justify using the winkey in your app ?... that doesn't sound very wise but, as I said before, use the winkey however you like.  Be my guest.  Go for it.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018