Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

User Image
Beak
41 discussion posts
As shown in the screenshot below, I have a bunch of Functions that I've created HotKeys for that are all related to one another. What I need is to figure out how to automate disabling and enabling the HotKeys for just those specific Functions and not any others. I'm already aware of the default
Toggle HotKeys
Function, but I don't want to enable/disable HotKeys globally. Is this possible with a Scripted Function? If so, can someone please help me set it up?

https://www.displayfusion.com/Discussions/Download/?ID=0197470d-71f0-7076-827d-86c89d24c48f
• Attachment: O4YqdaRFN5.png [10,644 bytes]
O4YqdaRFN5.png
O4YqdaRFN5.png
2 days ago (modified 2 days ago)  • #1
User Image
JLJTGR
115 discussion posts
I took a gander through the APIs and there isn't a straighforward way to do this. You cannot enable/disable/add/remove hotkeys to DF functions through scripting.

The only thought that came to mind is to convert your functions to scripted functions, then inside each script it checks a saved setting to see if it should actually perform work. The hotkeys always run the script, but the script can decide to abort and do nothing. Finally, another couple scripts to enable/disable the setting value to allow/disallow your other scripted functions.

The annoying part would be to convert your existing functions to scripted functions. (presumably, since I don't know how complicated your functions are)
1 day ago  • #2
User Image
Beak
41 discussion posts
Quote:
I took a gander through the APIs and there isn't a straighforward way to do this. You cannot enable/disable/add/remove hotkeys to DF functions through scripting.

The only thought that came to mind is to convert your functions to scripted functions, then inside each script it checks a saved setting to see if it should actually perform work. The hotkeys always run the script, but the script can decide to abort and do nothing. Finally, another couple scripts to enable/disable the setting value to allow/disallow your other scripted functions.

The annoying part would be to convert your existing functions to scripted functions. (presumably, since I don't know how complicated your functions are)


Thanks for your response, those sound like great ideas! They are Scripted Functions. I have ten Multi Clipboard Copy functions and ten corresponding Multi Clipboard Paste functions. The first of each are below.
https://www.displayfusion.com/Discussions/Download/?ID=019751eb-1188-760d-9c13-b35b8a7e47aa

Multi-Clipboard_Copy_0
:

Code

using System;

/*
   Works for Function names like:
     Multi-Clipboard_Copy_0
     Multi-Clipboard_Paste_7
*/
public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // 1) Figure out slot (0-9) and mode (Copy / Paste) from the Function’s name
        string fnName = BFS.General.GetCurrentScriptName();   // e.g. "Multi-Clipboard_Copy_3"
        bool isCopy  = fnName.Contains("_Copy_",  StringComparison.OrdinalIgnoreCase);
        bool isPaste = fnName.Contains("_Paste_", StringComparison.OrdinalIgnoreCase);

        // Extract last character → digit
        char lastChar = fnName[fnName.Length - 1];
        if (!char.IsDigit(lastChar)) return;          // safety check
        int slot = lastChar - '0';                   // '0' -> 0, … '9' -> 9
        string keyName = $"MultiClip{slot}";

        // 2) COPY  -----------------------------------------------------
        if (isCopy)
        {
            BFS.Clipboard.Copy();                    // same as Ctrl+C
            BFS.General.Sleep(100);                  // tiny “ClipWait”
            BFS.ScriptSettings.WriteValue(
                keyName,
                BFS.Clipboard.GetText() ?? string.Empty);
            return;
        }

        // 3) PASTE -----------------------------------------------------
        if (isPaste)
        {
            string stored = BFS.ScriptSettings.ReadValue(keyName);
            if (!string.IsNullOrEmpty(stored))
            {
                BFS.Clipboard.SetText(stored);
                BFS.Clipboard.Paste();               // same as Ctrl+V
            }
        }
    }
}


Multi-Clipboard_Paste_0
:

Code

using System;

/*
   Works for Function names like:
     Multi-Clipboard_Copy_0
     Multi-Clipboard_Paste_7
*/
public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // 1) Figure out slot (0-9) and mode (Copy / Paste) from the Function’s name
        string fnName = BFS.General.GetCurrentScriptName();   // e.g. "Multi-Clipboard_Copy_3"
        bool isCopy  = fnName.Contains("_Copy_",  StringComparison.OrdinalIgnoreCase);
        bool isPaste = fnName.Contains("_Paste_", StringComparison.OrdinalIgnoreCase);

        // Extract last character → digit
        char lastChar = fnName[fnName.Length - 1];
        if (!char.IsDigit(lastChar)) return;          // safety check
        int slot = lastChar - '0';                   // '0' -> 0, … '9' -> 9
        string keyName = $"MultiClip{slot}";

        // 2) COPY  -----------------------------------------------------
        if (isCopy)
        {
            BFS.Clipboard.Copy();                    // same as Ctrl+C
            BFS.General.Sleep(100);                  // tiny “ClipWait”
            BFS.ScriptSettings.WriteValue(
                keyName,
                BFS.Clipboard.GetText() ?? string.Empty);
            return;
        }

        // 3) PASTE -----------------------------------------------------
        if (isPaste)
        {
            string stored = BFS.ScriptSettings.ReadValue(keyName);
            if (!string.IsNullOrEmpty(stored))
            {
                BFS.Clipboard.SetText(stored);
                BFS.Clipboard.Paste();               // same as Ctrl+V
            }
        }
    }
}


I don't know how to modify these functions to do what you had suggested—if you know how to do it, would you mind modifying these to incorporate your suggested changes? What I need is for the HotKeys of these Scripted Functions to only be active whenever a specific
.exe
is running and then have the HotKeys not be active whenever the specified
.exe
is not running.
• Attachment: Bw1T5oWsk5.png [38,452 bytes]
Bw1T5oWsk5.png
Bw1T5oWsk5.png
18 hours ago (modified 18 hours ago)  • #3
User Image
JLJTGR
115 discussion posts
If your logic is to disable the functionality when a program is not running, this is significantly easier.

Just put the following code at the top of your Run() methods. (line 12)

Code

if(BFS.Application.IsAppRunningByFile(@"*\notepad.exe") == false)
    return;

Then replace "notepad.exe" with whatever your program is. The return statement will prevent the rest of the code from running when that program is not detected by DF.

The only annoying part is that DisplayFusion will show notifications for any scripted function running... which these still are. You may wish to change the global Advanced Setting, "Disable Notification for Scripted Functions Running".
17 hours ago  • #4
User Image
Beak
41 discussion posts
Quote:
If your logic is to disable the functionality when a program is not running, this is significantly easier.

Just put the following code at the top of your Run() methods. (line 12)

Code

if(BFS.Application.IsAppRunningByFile(@"*\notepad.exe") == false)
    return;

Then replace "notepad.exe" with whatever your program is. The return statement will prevent the rest of the code from running when that program is not detected by DF.

The only annoying part is that DisplayFusion will show notifications for any scripted function running... which these still are. You may wish to change the global Advanced Setting, "Disable Notification for Scripted Functions Running".


Is there some way to enable the functionality when the specified process is running?
17 hours ago  • #5
User Image
JLJTGR
115 discussion posts
That's what it does. If the application is not running, the function will abort. So if it is running, the function will proceed as normal. If I just don't understand you, change "false" to "true" in the if statement to do the opposite of what it does now.
17 hours ago  • #6
User Image
Beak
41 discussion posts
Quote:
That's what it does. If the application is not running, the function will abort. So if it is running, the function will proceed as normal. If I just don't understand you, change "false" to "true" in the if statement to do the opposite of what it does now.


My apologies, you're right. I got all mixed up and didn't correctly wrap my head around it.
10 hours ago  • #7
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)