Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable Caps Lock regular function #67

Closed
gurkoz opened this issue Feb 3, 2021 · 16 comments
Closed

Option to disable Caps Lock regular function #67

gurkoz opened this issue Feb 3, 2021 · 16 comments

Comments

@gurkoz
Copy link

gurkoz commented Feb 3, 2021

Hey!

First, love the script and everything about it! Thanks for putting time and effort into creating it. Hopefully you will continue to update it as i now have adapted it fully into my everyday use and it's awesome!

I Just have one suggestion, and please forgive me if this is the wrong place to submit this, not really too common with GitHub.

Anyway, the Caps Lock key is perfect for the usage of this script, love it. The only thing is, i never use the "regular" function of the standard Caps Lock key as i only use Shift when needed. So, sometimes when switching desktops i end up with the Caps Lock function turned on resulting in capital letters.

Is there any way to configure Caps Lock to only toggle desktops and not the "regular" function?

Keep up the great work!

(Tried to label this as an suggestion or enhancement but couldn't find out how.)

@Elijas
Copy link
Collaborator

Elijas commented Feb 3, 2021

Hi @gurkoz,

Thank you for your kind words! I'm glad you've found it useful. You're in the right place - these Github issue boards is where everyone helps each other out 👍 Don't worry about tags, at the moment it's up to the maintainers to manage them. Now to the question at hand:

How to disable Capslock

To disable CapsLock functionality when it's clicked on it's own, add a new line with these contents at the end of user_config.ahk

CapsLock::Return

Then restart the script.

Alternative: make Capslock do other things

You can make CapsLock do other things, for example open the Windows overview, which in all Windows 10 computers is opened with Win+Tab. Note, in AHK # means Win.

Add a new line with these contents at the end of user_config.ahk

CapsLock::Send, #{Tab}

Then restart the script.

Please, let me know if it works for you 😊

@gurkoz
Copy link
Author

gurkoz commented Feb 4, 2021

Woaw that's insanely useful! I didn't think of actually using Caps Lock for this. Fits perfectly since i sometimes do bring up the overview but always found the shortcut to be awkward. This is great!

Thanks for the quick response and this fix. Didn't think this could be any more awesome! Love it!

@Elijas
Copy link
Collaborator

Elijas commented Feb 4, 2021

Awesome! Let us know if you'd have any more questions / suggestions.

Thanks for using the script 🙌

@Jackiexiao
Copy link

Jackiexiao commented Jun 23, 2021

I follow instructions above, but sometimes it still activate CapsLock.... when I switch from desktop

@gurkoz
Copy link
Author

gurkoz commented Jun 23, 2021

Yeah, i'd like to join in by saying that, still super usefull and great and all, but it still messes up now and again. You need to go through the process of suspending the script, turning off Caps Lock and then start the script again. It's a hassle but i've learned to live with it. Happens a few times every day. Ofc, would be great if this wasn't the case. I generally NEVER use Caps Lock (the caps function) so perhaps it's possible to disable it in some other way also. Only use SHIFT key.

@Jackiexiao
Copy link

@gurkoz you don't need to restart script, just press win + CapLock or Alt + CapLock or any key combined with CapLock. But it is still inconvenient...

@Jackiexiao
Copy link

Jackiexiao commented Jul 15, 2021

the above method didn't work well..... it toggle CapLocks occasionally... I figure out another way to solve this problem

First, you need to find a key that's rarely useless, for example F9 or F10, and use window's PowerToy to remap CapLocks to F9

image

Then change user_config.ahk, replace every CapLocks to F9

F9 & 1::switchDesktopByNumber(1)
F9 & 2::switchDesktopByNumber(2)
F9 & 3::switchDesktopByNumber(3)
....

to fix occasionally toggle Caplocks, you can map F10 to Caplocks
image

@WilsonNet
Copy link

WilsonNet commented Dec 5, 2021

According to this tutorial

you can make disabling capslock more robust by using this *CapsLock::Return

I still get capslock triggered a few times, but it's way less frequent.

I couldn't find a way to reproduce whenever I want the capslock triggering, so I don't know what is causing it.

@serranomorante
Copy link

Tried all this solutions. CapsLk still triggering sometimes. Very annoying.
I ended up using just the Win key (Side note: in my computer, Win + n doesn't actually do anything, but the other shortcuts like Win + R... do work). The hand position is not as comfortable as with CapsLk, but it works without conflicting with anything, which I like (btw, I'm just using the number desktop switching functionality, nothing else).

#1::switchDesktopByNumber(1)
...

Thank you so much for this tool, works so much better than others I have tried. Well done!

@WilsonNet
Copy link

WilsonNet commented Dec 12, 2021

According to this tutorial

you can make disabling capslock more robust by using this *CapsLock::Return

I still get capslock triggered a few times, but it's way less frequent.

I couldn't find a way to reproduce whenever I want the capslock triggering, so I don't know what is causing it.

Just discovered the cause for Capslock triggering even with *

Modifier + Capslock is safe, but Capslock + Key is still trigerring, eg: Capslock + k

I still don't know how to disable that, but I think that is the solution.

@WilsonNet
Copy link

WilsonNet commented Dec 12, 2021

Found the solution
Adding SetCapsLockState, AlwaysOff in the first line of desktop_switcher.ahk seems to have solved it

Source:
https://www.autohotkey.com/docs/commands/SetNumScrollCapsLockState.htm

@serranomorante
Copy link

Found the solution Adding SetCapsLockState, AlwaysOff in the first line of desktop_switcher.ahk seems to have solved it

Source: https://www.autohotkey.com/docs/commands/SetNumScrollCapsLockState.htm

For now, after 3 hours of using this solution, I haven't notice any problems. Thank you!

@serranomorante
Copy link

Found the solution Adding SetCapsLockState, AlwaysOff in the first line of desktop_switcher.ahk seems to have solved it

Source: https://www.autohotkey.com/docs/commands/SetNumScrollCapsLockState.htm

I would still consider this as the solution, even though when I use Caps Lock very very frequently and typing very fast the functionality kinda gets stuck and the desktop switching happens even without pressing the Caps Lock, only by pressing the numbers. This behaviour is hard to replicate.

Also, another problem (this one more easy to replicate) that happens to me is when Im using a heavy app (Illustrator in my case) and it gets unresponsive, then the Caps Lock recovers its regular functionality (uppercasing words), at least during the time that Illustrator gets unresponsive.

My tought (very vague) is that all this has something to do with Autohotkey not being as performant as a native solution would be, native like C++ or .NET

Still a wonderful tool 💘

@serranomorante
Copy link

serranomorante commented Dec 18, 2021

Hi, I have found the solution for my particular use case. I'm not trying to force you to replicate my config, but it might guide you to your own solution.

Important:
I know almost nothing about autohotkeys.
I'm not disabling the CapsLock functionality, I need it, I'm just solving (I hope once for all) the problem of CapsLock getting activated or stuck at random times, which for me its a big achievement jejeje, that thing was really annoying.

My use case goes like this:

  • For now, I don't need more than just switching between my different virtual desktops on a efficient manner.
  • I would only use the CapsLock + n shortcut for the switching (I'm not interest in doing anything with numpads or any other keys)

Things I dont want or like to happen:

  • CapsLock getting "stuck" which result in unintentional and random virtual desktop switching.
  • CapsLock uppercasing functionality appearing randomly.

Things I had to sacrifice:

  • Not being able to just mantain the CapsLock key pressed while changing between numbers. I have to press and release CapsLock + n in order for anything to happend. But hey, this is the heart of the solution.

How did I solved it:

I didn't add anything to my user_config.ahk. I just leave this part because thats the shorcut I need CapsLock + n

CapsLock & 1::switchDesktopByNumber(1)  
CapsLock & 2::switchDesktopByNumber(2)  
CapsLock & 3::switchDesktopByNumber(3)  
CapsLock & 4::switchDesktopByNumber(4)  
CapsLock & 5::switchDesktopByNumber(5)  
CapsLock & 6::switchDesktopByNumber(6)  
CapsLock & 7::switchDesktopByNumber(7)  
CapsLock & 8::switchDesktopByNumber(8)  
CapsLock & 9::switchDesktopByNumber(9)

Step 1

The important part its t in he desktop_switcher.ahk file, the only changes you need to make on this file are the following:

Inside that file, look for this function: _switchDesktopToTarget
At the end of that function, just right before the curly bracket }, add this 2 lines (I included the closing bracket just for demonstration):

    ...
    If (GetKeyState("CapsLock","T"))
          SetCapsLockState,Off
}

This basically says: Once you have executed the switching, force the CapsLock to turn off in case it got "virtually stuck".

Step 2

Then, look for other function called switchDesktopByNumber, just right after the updateGlobalVariables() line, insert the following:

KeyWait, CapsLock

This basically says: I'm not doing anything until you release the CapsLock key (and the number key). Release it and I would start switching desktops.

Save and reload the script as administrator.

Summary
We have just modified 2 functions inside the desktop_switcher.ahk file. The end result should look like this.
Please remember to leave everything else inside the file as is.

_switchDesktopToTarget function

_switchDesktopToTarget(targetDesktop)
{
    ; Globals variables should have been updated via updateGlobalVariables() prior to entering this function
    global CurrentDesktop, DesktopCount, LastOpenedDesktop

    ; Don't attempt to switch to an invalid desktop
    if (targetDesktop > DesktopCount || targetDesktop < 1 || targetDesktop == CurrentDesktop) {
        OutputDebug, [invalid] target: %targetDesktop% current: %CurrentDesktop%
        return
    }

    LastOpenedDesktop := CurrentDesktop

    ; Fixes the issue of active windows in intermediate desktops capturing the switch
    ; shortcut and therefore delaying or stopping the switching sequence. This also 
    ; fixes the flashing window button after switching in the taskbar. 
    ; More info: https://github.com/pmb6tz/windows-desktop-switcher/pull/19
    WinActivate, ahk_class Shell_TrayWnd

    ; Go right until we reach the desktop we want
    while(CurrentDesktop < targetDesktop) {
        Send {LWin down}{LCtrl down}{Right down}{LWin up}{LCtrl up}{Right up}
        CurrentDesktop++
        OutputDebug, [right] target: %targetDesktop% current: %CurrentDesktop%
    }

    ; Go left until we reach the desktop we want
    while(CurrentDesktop > targetDesktop) {
        Send {LWin down}{LCtrl down}{Left down}{Lwin up}{LCtrl up}{Left up}
        CurrentDesktop--
        OutputDebug, [left] target: %targetDesktop% current: %CurrentDesktop%
    }

    ; Makes the WinActivate fix less intrusive
    Sleep, 50

    focusTheForemostWindow(targetDesktop)
    If (GetKeyState("CapsLock","T"))
      SetCapsLockState,Off
}

and switchDesktopByNumber function.

switchDesktopByNumber(targetDesktop)
{
    global CurrentDesktop, DesktopCount
    updateGlobalVariables()
    KeyWait, CapsLock
    _switchDesktopToTarget(targetDesktop)
}

At first, having to press and release its not the most intuitive thing, but it gets easier with the time.

@AndreuSCK
Copy link

AndreuSCK commented Jun 10, 2022

Hi, Any of these solutions have already been added to master code? @gorbunovav
not sure if I still should apply your fix @serranomorante, i want to disable caps lock, but still have a way to activate it,
like shift + capslock or double tap fast capslock, thanks @gurkoz

@serranomorante
Copy link

Hi, Any of these solutions have already been added to master code? @gorbunovav not sure if I still should apply your fix @serranomorante, i want to disable caps lock, but still have a way to activate it, like shift + capslock or double tap fast capslock, thanks @gurkoz

Hi. It was a workaround. I ended up using Dextpot and I'm very happy so far.

My solution above kinda works but it still has it drawbacks.

I would strongly suggest Dexpot. It's free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants