StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
eugenes  
#1 Posted : Thursday, February 18, 2021 7:48:58 PM(UTC)
eugenes

Rank: Member

Reputation:

Groups: Approved
Joined: 12/2/2019(UTC)
Posts: 20

Thanks: 2 times
Hi

I wanted to bind the NumLock hotkey to run a specific application or to bring it up if it's already run. Moreover, next Numlock press must minimize the app.

Cany you help me with that?

Thanks

Edited by user Thursday, February 18, 2021 7:49:59 PM(UTC)  | Reason: Not specified

Rob  
#2 Posted : Friday, February 19, 2021 2:34:19 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This is an example using notepad - it only is matching on partial title, but it gives you a starting point.

I created a hotkey which is bound to NUMLOCK:
Code:
var wnd = sp.WindowsFromTitlePartial("- Notepad");
if(wnd.Count() === 0) {
    sp.Run("notepad");
} else {
    if(wnd.First().Minimized) {
        wnd.First().Restore();
    } else {
        if(sp.ForegroundWindow().HWnd.ToString() !== wnd.First().HWnd.ToString()) {
            wnd.First().Activate();
        } else {
            wnd.First().Minimize();
        }
    }
}

If notepad is not open, it will run notepad. If notepad is open but not active, it will activate it - if notepad is active, it will minimize it.
thanks 1 user thanked Rob for this useful post.
eugenes on 2/19/2021(UTC)
eugenes  
#3 Posted : Friday, February 19, 2021 7:04:44 AM(UTC)
eugenes

Rank: Member

Reputation:

Groups: Approved
Joined: 12/2/2019(UTC)
Posts: 20

Thanks: 2 times
It works well, but sometimes it turns numlock off. Please add a string that will check the numlock status and turns it on
Rob  
#4 Posted : Friday, February 19, 2021 2:25:27 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
I also updated it to restore the window maximized if that was the state before minimizing.
Code:
var wnd = sp.WindowsFromTitlePartial("- Notepad");
if(wnd.Count() === 0) {
    sp.Run("notepad");
} else {
    if(wnd.First().Minimized) {
        if(sp.GetStoredBool("WindowMaximized")) {
            wnd.First().Maximize();
        } else {
            wnd.First().Restore();
        }
    } else {
        if(sp.ForegroundWindow().HWnd.ToString() !== wnd.First().HWnd.ToString()) {
            wnd.First().Activate();
        } else {
            sp.StoreBool("WindowMaximized", wnd.First().Maximized);
            wnd.First().Minimize();
        }
    }
}

sp.Sleep(250);
if(!sp.IsKeyToggled(vk.NUMLOCK)) {
    sp.SendVKey(vk.NUMLOCK);
}

Edited by user Friday, February 19, 2021 2:26:07 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
eugenes on 2/19/2021(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.