<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>DisplayFusion RSS: Share Context between scripts or allow assigning multiple keybinds to a single script.</title>
<atom:link href="https://www.displayfusion.com/Discussions/RSS/?TopicID=01987cde-0ce9-74ed-8cdf-ff2858027a6c" rel="self" type="application/rss+xml" />
<link>https://www.displayfusion.com/Discussions/RSS/?TopicID=01987cde-0ce9-74ed-8cdf-ff2858027a6c</link>
<description>DisplayFusion RSS: Share Context between scripts or allow assigning multiple keybinds to a single script.</description>
<lastBuildDate>Sun, 12 Apr 2026 16:12:36 GMT</lastBuildDate>
<language>en</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>https://www.displayfusion.com/Discussions/RSS/?TopicID=01987cde-0ce9-74ed-8cdf-ff2858027a6c</generator>
<item>
<title>RE: Share Context between scripts or allow assigning multiple keybinds to a single script.</title>
<link>https://www.displayfusion.com/Discussions/View/share-context-between-scripts-or-allow-assigning-multiple-keybinds-to-a-single-script/?ID=01987cde-0ce9-74ed-8cdf-ff2858027a6c#2</link>
<pubDate>Wed, 06 Aug 2025 17:27:38 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/share-context-between-scripts-or-allow-assigning-multiple-keybinds-to-a-single-script/?ID=01987cde-0ce9-74ed-8cdf-ff2858027a6c#2</guid>
<category>DisplayFusion</category>
<description><![CDATA[This is currently on our feature request list, so I've added your vote to it. We'll be sure to let you know if/when we're able to implement it in the future.
Thanks!]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
This is currently on our feature request list, so I've added your vote to it. We'll be sure to let you know if/when we're able to implement it in the future.<br/>
<br/>
Thanks!
</div>
]]></content:encoded>
</item>
<item>
<title>Share Context between scripts or allow assigning multiple keybinds to a single script.</title>
<link>https://www.displayfusion.com/Discussions/View/share-context-between-scripts-or-allow-assigning-multiple-keybinds-to-a-single-script/?ID=01987cde-0ce9-74ed-8cdf-ff2858027a6c</link>
<pubDate>Wed, 06 Aug 2025 00:53:04 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/share-context-between-scripts-or-allow-assigning-multiple-keybinds-to-a-single-script/?ID=01987cde-0ce9-74ed-8cdf-ff2858027a6c</guid>
<category>DisplayFusion</category>
<description><![CDATA[Since DisplayFusion only allows a 1:1 mapping per hotkey & script, I have 20 copies of the same script with the only differences being 2 variables at the top: private const int NUMPAD_KEY = 0...9;
and private const bool CTRL = true|false
.
Ideally, I'd be able to assign all variants of WinKey ...]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
Since DisplayFusion only allows a 1:1 mapping per hotkey & script, I have 20 copies of the same script with the only differences being 2 variables at the top: <div class="Inline"><pre>private const int NUMPAD_KEY = 0...9;</pre></div> and <div class="Inline"><pre>private const bool CTRL = true|false</pre></div>.  <br/>
<br/>
Ideally, I'd be able to assign all variants of <div class="Inline"><pre>WinKey + Numpad_#</pre></div> and <div class="Inline"><pre>Ctrl + WinKey + Numpad_#</pre></div> keybinds to one function.  The inability to do so results in workarounds & my current issue.  <br/>
I need to share context between these 20 function variants: wich windows they've moved, from where, & where to. Currently it works something like this:  <br/>
<br/>
<div id="" class="col-md-12 BoxWrap"><div class="Box table-responsive"><a name="code" style="width:0; height:0;"></a><h2 class="TableTitle" style="border:0"><div class="TableTitleText">Code</div><div class="TitleButtons"><div class="TableTitleButton"><a href="#" onclick="return false;" data-clipboard-target="#code019d8277659377ef8522732b69f6165e" class="ClipboardCopyControl"><img src="https://www.displayfusion.com/MediaCommon/SVGs/FontAwesome/clone.blue.svg" style="box-sizing:border-box;position:relative;overflow:hidden;vertical-align:middle !important;width:auto;max-width:16px;height:16px;" /><span class="Text">Copy</span></a></div><div class="TableTitleButton"><a href="#" onclick="bfs.util.codeEditorSelectAll('code019d8277659377ef8522732b69f6165eJs'); return false;"><img src="https://www.displayfusion.com/MediaCommon/SVGs/FontAwesome/square-check.blue.svg" style="box-sizing:border-box;position:relative;overflow:hidden;vertical-align:middle !important;width:auto;max-width:16px;height:16px;" /><span class="Text">Select All</span></a></div></div></h2><div class="TableTitleContent table-responsive"><div class="AceEditorWrapper" style="border-top:solid 1px var(--color-default-border);padding:0"><pre id="code019d8277659377ef8522732b69f6165eJs" contenteditable="true" spellcheck="true" class="skiptranslate" style="width:100%; min-height:75px;">public static partial class DisplayFusionFunction {

  record HistoricPosition(
    bool Maximized, 
    int Monitor, 
    Point Cell, 
    Point RowsCols, 
    Rectangle Pos, 
    int? NumKey = null, 
    bool? Ctrl = null
  );

  class ExpirableEntryList(uint Age): List&lt;HistoricPosition&gt; { 
    public uint Age { get; set; } = Age;
  };

  class Context: Dictionary&lt;uint, ExpirableEntryList&gt; {
    const uint MAX_AGE = 12; // 12hrs
    static readonly DateTime Epoch = new DateTime(2025, 1, 1);
    
    static uint Now =&gt; (uint)DateTime.Now.Subtract(Epoch).TotalHours;
    
    static uint ToKey(IntPtr whnd) =&gt; unchecked((uint)whnd.ToInt32());
    
    public ExpirableEntryList Get(IntPtr whnd) =&gt; this.TryGetValue(ToKey(whnd), out var list) ? list : null;
    
    public void Load() {
      this.Clear();
      uint now = (uint)DateTime.Now.Subtract(Epoch).TotalHours;
      var dict = JsonSerializer.Deserialize&lt;Dictionary&lt;uint, ExpirableEntryList&gt;&gt;(
        BFS.ScriptSettings.ReadValue("NumpadPositions.WindowHistory") ?? "{}"
      );
      foreach(var (Key, Value) in dict) {
        if(Value.Age &lt; now - MAX_AGE) continue; # Skip expired entries
        this.Add(Key, Value);
      }
    }

    public void AddRecord(IntPtr whnd, HistoricPosition entry) {
      var list = this.Get(whnd);
      if(list != null) {
        list.Age = Now;
        list.Add(entry);
      } else { 
        this.Add(ToKey(whnd), new ExpirableEntryList(now) { entry });
      }
      BFS.ScriptSettings.WriteValue("NumpadPositions.WindowHistory", JsonSerializer.Serialize(this));
    }
  }
}</pre><textarea id="code019d8277659377ef8522732b69f6165e" name="code019d8277659377ef8522732b69f6165e" style="position:absolute; top:0; left:-999999px; width:1px; height:1px;"></textarea></div>
</div></div></div><br/>
The issues with this are:<br/>
<ul class="ListBullet">
<li>Kind of annoying to have to do.</li>
<li>It persists when DisplayFusion is restarted.</li>
<li>It persist on reboots.</li>
<li>Collisions could happen on the HWND key. There's still more than enough entropy when coercing the 64bit HWND to 32bit. However, Windows handles start over across reboots... And my settings persist...</li>
<li>There's 20 script variants so I can't check the state of a static variable to detect if DisplayFusion was restarted then clear the ScriptSettings, each script has its own distinct static variables.</li></ul>
<br/>
At least one of the following would be greatly appreciated in the BFS API. <br/>
<ul class="ListBullet">
<li>Ability to assign multiple keybinds to a single script. The Script could then check <div class="Inline"><pre>BFS.Input.IsKeyDown</pre></div> to figure out what it needs to do from there.</li>
<li>A session storage/settings API.</li>
<li>Perhaps an options param that can specify ExpirationPolicy to <div class="Inline"><pre>BFS.ScriptSettings.WriteValue</pre></div></li>
<li>Ability to Query basic info like System Uptime, Session Uptime, DisplayFusion Start Time.</li></ul>
</div>
]]></content:encoded>
</item>
</channel>
</rss>