Strange event crosstalk: Mouse & Keyboard, WPF & Rx?

I've written a really tiny WPF + Rx program in VS 2010, and it has some unexpected behavior -- seemingly picking up alt-key events in the mouse-event observables. I'd be grateful for advice on any of

  1. what's specifically wrong
  2. ideas or tools on how to diagnose it further on my own [e.g., are there some tools that instruments the code to track and log all events that get fired so I can see more clearly what's happening?]
  3. how to understand the behavior -- is it "by design"? Am I misusing WPF or Rx or both?
  4. how to get the behavior I'd rather have, described below

First, what it does correctly is fire mouse move observers starting from a mouse down and ending with a mouse up. The particular test observer I have just puts the proper mouseDown + mouseUp coordinates in the TitleBar of the Window (see code + XAML below).

The strangeness starts if I press and release the alt key while the mouse is down. That seems immediately to stop the mouseMove event observers. Now, if I release the mouseButton, the mouseMove event observers start up again, and continue until I either generate a new mouseDown or press and release alt again. Further more, if I go through this sequence, namely

mouseDown mouseMove alt-key down alt-key up mouseUp alt-key down alt-key up

and then, the normal

mouseDown mouseMove

the print in the Title bar has some odd flashing, telling me that there are other, extraneous events getting tracked and pumped through my observer lambda.

I haven't been able to make this fail with keys other than alt, deepening the mystery.

The desired behavior could be

  1. either checking for alt key state explicitly in the mouse-move handlers
  2. or separate event streams for the keyDown and keyUp events, and I'll figure out the interleaving in my code

But, for sure, having this behavior and, worse, having no clue how to proceed to understand it, is really bad. I'll be grateful for any ideas!

(NOTE: add references to System.coreex, System.Reactive, and System.Interactive)

using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Input; namespace DownAndMoveTest { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); (from mDown in this.GetLeftMouseDownObservable(). Do(e => this.Title = "DOWN: " + e.EventArgs.GetPosition(this).ToString()) let mDownP = mDown.EventArgs.GetPosition(this) from mMove in this.GetMouseMoveObservable().TakeUntil(this.GetLeftMouseUpObservable()) select new { D = mDownP, M = mMove.EventArgs.GetPosition(this) }).Subscribe(ps => { this.Title = String.Format( "Window MouseDown({0:G}, {1:G}), MouseMove({2:G}, {3:G})", ps.D.X, ps.D.Y, ps.M.X, ps.M.Y); }); } } public static partial class UIElementExtensions { public static IObservable<IEvent<MouseButtonEventArgs>> GetLeftMouseDownObservable(this UIElement uiElement) { return Observable.FromEvent<MouseButtonEventHandler, MouseButtonEventArgs>( h => new MouseButtonEventHandler(h), h => uiElement.MouseLeftButtonDown += h, h => uiElement.MouseLeftButtonDown -= h); } public static IObservable<IEvent<MouseEventArgs>> GetMouseMoveObservable(this UIElement uiElement) { return Observable.FromEvent<MouseEventHandler, MouseEventArgs>( h => new MouseEventHandler(h), h => uiElement.MouseMove += h, h => uiElement.MouseMove -= h); } public static IObservable<IEvent<MouseButtonEventArgs>> GetLeftMouseUpObservable(this UIElement uiElement) { return Observable.FromEvent<MouseButtonEventHandler, MouseButtonEventArgs>( h => new MouseButtonEventHandler(h), h => uiElement.MouseLeftButtonUp += h, h => uiElement.MouseLeftButtonUp -= h); } } }

and its XAML

<Window x:Class="DownAndMoveTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> </Grid> </Window>

-------------Problems Reply------------

Does your application have a main menu? Pressing the alt key focuses the menu bar, and pressing alt again returns focus to whatever had focus before. This would explain the functionality you are seeing. (It does not look like an Rx issue)

Category:wpf Views:0 Time:2010-11-26

Related post

  • How to tell if a button click event was triggered by keyboard or mouse in WPF? 2008-12-06

    Is there a simple way to tell what triggered Click event of a Button apart from setting multiple flags in Mouse/Key Up/Down event handlers? I'm currently only interested in distinguishing mouse from everything else, but it would be nice to handle Sty

  • java.awt.Robot: how to send mouse/keyboard events to a specific window? with cross-platform support? 2011-11-26

    So from this question In Java Swing how do you get a Win32 window handle (hwnd) reference to a window? it appears that I can get the window32 handle . would it be possible for java.awt.Robot to send mouse/keyboard events to that window handle? someti

  • Selection change event for MFC CListCtrl, caused by mouse/keyboard input only 2010-01-28

    i am using an mfc ListCtrl, is there anyway to know if a selection change was caused by mouse/keyboard input rather than a programatic change? i am after the same behaviour as ON_LBN_SELCHANGE for a listbox. thanks --------------Solutions------------

  • Problems With Mouse/Keyboard Input 2012-05-12

    Note that as best I can determine, the majority of this applies to every version of Windows since at least XP. I've been working for the better part of 9 months to try to track down the cause of several bizarre glitches concerning keyboard/mouse inpu

  • Mouse & Keyboard Center stops working 2013-09-08

    Hi, I'm running Windows 8, and have just purchased a Wireless 800 Desktop Set. I was previously running an old Wireless Multimedia keyboard, not supported by Mouse & Keyboard Center, so was running Intellitype & Intellipoint. My desktop set w

  • Can windows detect when a monitor, mouse, keyboard is disconnected? 2009-09-17

    Can windows detect when a monitor, mouse or keyboard is disconnected from the computer? If so what Win32 API is used for this? --------------Solutions------------- Not sure about the monitor, but the keyboard and mouse being disconnected should fire

  • Mouse/Keyboard input in OSX without Cocoa 2011-03-22

    I am writing an application in C++ using CGL/OpenGL, and need keyboard/mouse input. I was trying to avoid Objective-C and Cocoa if possible. I am aware that one can capture input using Carbon, but seems that Carbon is slowly being phased out, plus it

  • Java Applet Game Loop stops Mouse/Keyboard Input? 2011-07-08

    I got a problem I couldn't get to work after about 2 Hours of trying. I want to have a loop that do 2 Methods (Draw and update) but also listen to Mouse/Keyboard events. I have a loop that Draws and Updates, but does nothing outside of the loop ( Lis

  • Programmatically Disable Mouse & keyboard 2011-07-21

    I would like to programmatically disable mouse & keyboard input temporarily on a mac (using Objective C/C/Unix) & then reenable them. --------------Solutions------------- I have made a small open source application that allows you to selectiv

  • Mouse & Keyboard Slow and/or Unresponsive 2012-05-16

    My mouse and keyboard seem to hang up from time to time. Can't pin down a reason for this condition. As for the keyboard, I can be typing along and the letters just stop -- sometimes they will "catch up," and sometimes they will not. As for the mouse

  • Razer Tron Mouse & Keyboard 2012-11-10

    A little concerned since the Hardware Compatibility webpage says both ARE compatible, however I own BOTH the mouse & keyboard and I know for a fact that they are BOTH "Not completely Compatible/Functional under Windows-8. They both worked great u

  • Mouse, keyboard and the broadband disconnects randomly 2014-01-16

    Mouse goes dead randomly & at different times so does the keyboard and the broadband disconnects randomly also even though it is operating on another PC connected to the modem.__ I have changed power options to not turn off any time/anything incl

  • Microsoft Mouse & Keyboard Center 'Stopped Working" 2014-03-17

    I've started getting the message Microsoft Mouse & Keyboard Center has Stopped Working (see error report below) when Windows 8 starts. I've tried uninstalling and re-installing the latest version of the Mouse & Keyboard Center but still have

  • wedge mobile keyboard shows up as HID, won't show up in Microsoft mouse & keyboard center 2014-07-01

    My keyboard works, but it's shown as a generic bt keyboard in device manager and it wo't show up in microsoft's mouse & keyboard center. Any ideas? --------------Solutions------------- Hi KK, Please answer this question to get more clarity on thi

  • Windows running, but mouse / keyboard activity won't turn display on - sometimes.... 2015-01-01

    Hi, - Windows 7 64bit - Power Settings: Turn off display 5mins / Put Computer To Sleep: Never The problem is that when I come back to the machine after a period of time *sometimes* when I move the mouse and/or press a key on the keyboard the display

  • redirect mouse/keyboard input 2009-10-09

    Is there some other simple method to redirect mouse/keyboard input from one object to an object behind it. I have used mouseEnabled = false where the object in front is only a UIComponent and it works. However mouseEnabled,mouseChildren=false is not

  • Detecting browser capabilities and selective events for mouse and touch 2010-05-07

    I started using touch events for a while now, but I just stumbled upon quite a problem. Until now, I checked if touch capabilities are supported, and applied selective events based on that. Like this: if(document.ontouchmove === undefined){ //apply m

  • hide scrollbar while still able to scroll with mouse/keyboard 2010-07-20

    Possible Duplicate: How to disable browser or element scrollbar, but allow scrolling with wheel or arrow keys? I want to know if it is possible to hide the scrollbar, while scrolling is still enabled with mouse/keyboard. I tried to use CSS: overflow:

  • Move the mouse in wpf 2010-11-18

    I'm currently looking for a way to move the mouse in wpf. All I found was unmanaged method calls which I couldn't implement reliably. Is there an easy way to move the mouse cursor to some place, ie. after a doubleclick? I'm surely missing something h

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.241 (s). 11 q(s)