Permalink
Browse files

Keyboard (System Window), KeyMatch, KeyStates (Split): release keys o…

…n activation of a window that is no renderer.
  • Loading branch information...
1 parent 5c1c3df commit e9ad198ce1db289ac984231355d50a096032efb8 @gregsn gregsn committed Feb 26, 2014
@@ -11,7 +11,8 @@ public enum KeyNotificationKind
{
KeyDown,
KeyPress,
- KeyUp
+ KeyUp,
+ DeviceLost
}
public abstract class KeyNotification
@@ -58,4 +59,12 @@ public KeyUpNotification(Keys keyCode)
{
}
}
+
+ public class KeyboardLostNotification : KeyNotification
+ {
+ public KeyboardLostNotification()
+ : base(KeyNotificationKind.DeviceLost)
+ {
+ }
+ }
}
@@ -1,6 +1,6 @@
-<!DOCTYPE PATCH SYSTEM "http://vvvv.org/versions/vvvv45alpha31.5.dtd" >
- <PATCH nodename="C:\Work\anton-vvvv-sdk\vvvv45\lib\nodes\plugins\Keyboard (Devices Desktop) help.v4p">
- <BOUNDS height="10530" left="0" top="0" type="Window" width="14010">
+<!DOCTYPE PATCH SYSTEM "http://vvvv.org/versions/vvvv45debug31.7.dtd" >
+ <PATCH nodename="D:\dev\v45\vvvv\public\vvvv45\lib\nodes\plugins\Keyboard (Devices Desktop) help.v4p">
+ <BOUNDS height="10530" left="600" top="4620" type="Window" width="14010">
</BOUNDS>
<NODE componentmode="InABox" id="99" nodename="IOBOX (VALUE ADVANCED)" systemname="IOBox (Value Advanced)">
<BOUNDS height="0" left="3465" top="2685" type="Node" width="0">
@@ -195,7 +195,7 @@
</PIN>
<PIN pinname="Queue Mode" visible="1">
</PIN>
- <PIN pinname="Index" slicecount="5" values="0,1,2,3,4">
+ <PIN pinname="Index" slicecount="1" values="0">
</PIN>
<PIN pinname="Key Name Bin Size" visible="1" pintype="Output">
</PIN>
@@ -134,7 +134,12 @@ public void Subscribe()
throw new NotImplementedException();
}
- FSubscription = result.ObserveOn(FScheduler)
+ //on keyboard lost: keep toggle state when in toggle mode; in any other case just release the key
+ if (FKeyMode != KeyMode.Toggle)
+ result = result.Merge(FKeyboard.KeyNotifications.OfType<KeyboardLostNotification>().Select(_ => false));
+
+ FSubscription = result
+ .ObserveOn(FScheduler)
.Subscribe(v => Output = v);
}
@@ -26,13 +26,31 @@ namespace VVVV.Nodes.Input
Category = "Devices",
Version = "Window",
Help = "Returns the keyboard of the current render window.")]
- public class KeyboardNode : WindowMessageNode, IPluginEvaluate
+ public class KeyboardNode : WindowMessageNode, IPluginEvaluate, IPartImportsSatisfiedNotification
{
[Output("Device", IsSingle = true)]
public ISpread<Keyboard> KeyboardOut;
private PluginContainer FKeyboardStatesSplitNode;
+ [Import]
+ protected IHDEHost FHost;
+ private IObservable<KeyNotification> FDeviceLostNotifications;
+
+ public override void OnImportsSatisfied()
+ {
+ FDeviceLostNotifications =
+ Observable.FromEventPattern<WindowEventArgs>(FHost, "WindowSelectionChanged")
+ .Select(p => p.EventArgs.Window)
+ .OfType<Window>()
+ .Select(w => w.UserInputWindow != null)
+ .DistinctUntilChanged()
+ .Where(assigned => !assigned)
+ .Select(_ => new KeyboardLostNotification());
+
+ base.OnImportsSatisfied();
+ }
+
protected override void Initialize(IObservable<WMEventArgs> windowMessages)
{
var keyNotifications = windowMessages
@@ -54,7 +72,7 @@ protected override void Initialize(IObservable<WMEventArgs> windowMessages)
}
)
.OfType<KeyNotification>();
- KeyboardOut[0] = new Keyboard(keyNotifications);
+ KeyboardOut[0] = new Keyboard(keyNotifications.Merge(FDeviceLostNotifications));
// Create a keyboard states node for us and connect our keyboard out to its keyboard in
var nodeInfo = FIOFactory.NodeInfos.First(n => n.Name == "KeyStates" && n.Category == "Keyboard" && n.Version == "Split");
@@ -297,6 +315,11 @@ public void Evaluate(int spreadMax)
keyNameOut.RemoveAll(k => k == keyUp.KeyCode.ToString());
KeyCharOut[slice] = string.Empty;
break;
+ case KeyNotificationKind.DeviceLost:
+ keyCodeOut.SliceCount = 0;
+ keyNameOut.SliceCount = 0;
+ KeyCharOut[slice] = string.Empty;
+ break;
default:
throw new NotImplementedException();
}
@@ -29,7 +29,7 @@ public abstract class WindowMessageNode : IPluginBase, IPartImportsSatisfiedNoti
private readonly List<Subclass> FSubclasses = new List<Subclass>();
- public void OnImportsSatisfied()
+ public virtual void OnImportsSatisfied()
{
var windowMessages = Observable.FromEventPattern<WindowEventArgs>(FHost, "WindowAdded")
.Select(p => p.EventArgs.Window)

0 comments on commit e9ad198

Please sign in to comment.