Search Results

Search found 132 results on 6 pages for 'mousemove'.

Page 2/6 | < Previous Page | 1 2 3 4 5 6  | Next Page >

  • Generate Strongly Typed Observable Events for the Reactive Extensions for .NET (Rx)

    - by Bobby Diaz
    I must have tried reading through the various explanations and introductions to the new Reactive Extensions for .NET before the concepts finally started sinking in.  The article that gave me the ah-ha moment was over on SilverlightShow.net and titled Using Reactive Extensions in Silverlight.  The author did a good job comparing the "normal" way of handling events vs. the new "reactive" methods. Admittedly, I still have more to learn about the Rx Framework, but I wanted to put together a sample project so I could start playing with the new Observable and IObservable<T> constructs.  I decided to throw together a whiteboard application in Silverlight based on the Drawing with Rx example on the aforementioned article.  At the very least, I figured I would learn a thing or two about a new technology, but my real goal is to create a fun application that I can share with the kids since they love drawing and coloring so much! Here is the code sample that I borrowed from the article: var mouseMoveEvent = Observable.FromEvent<MouseEventArgs>(this, "MouseMove"); var mouseLeftButtonDown = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseLeftButtonDown"); var mouseLeftButtonUp = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseLeftButtonUp");       var draggingEvents = from pos in mouseMoveEvent                              .SkipUntil(mouseLeftButtonDown)                              .TakeUntil(mouseLeftButtonUp)                              .Let(mm => mm.Zip(mm.Skip(1), (prev, cur) =>                                  new                                  {                                      X2 = cur.EventArgs.GetPosition(this).X,                                      X1 = prev.EventArgs.GetPosition(this).X,                                      Y2 = cur.EventArgs.GetPosition(this).Y,                                      Y1 = prev.EventArgs.GetPosition(this).Y                                  })).Repeat()                          select pos;       draggingEvents.Subscribe(p =>     {         Line line = new Line();         line.Stroke = new SolidColorBrush(Colors.Black);         line.StrokeEndLineCap = PenLineCap.Round;         line.StrokeLineJoin = PenLineJoin.Round;         line.StrokeThickness = 5;         line.X1 = p.X1;         line.Y1 = p.Y1;         line.X2 = p.X2;         line.Y2 = p.Y2;         this.LayoutRoot.Children.Add(line);     }); One thing that was nagging at the back of my mind was having to deal with the event names as strings, as well as the verbose syntax for the Observable.FromEvent<TEventArgs>() method.  I came up with a couple of static/helper classes to resolve both issues and also created a T4 template to auto-generate these helpers for any .NET type.  Take the following code from the above example: var mouseMoveEvent = Observable.FromEvent<MouseEventArgs>(this, "MouseMove"); var mouseLeftButtonDown = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseLeftButtonDown"); var mouseLeftButtonUp = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseLeftButtonUp"); Turns into this with the new static Events class: var mouseMoveEvent = Events.Mouse.Move.On(this); var mouseLeftButtonDown = Events.Mouse.LeftButtonDown.On(this); var mouseLeftButtonUp = Events.Mouse.LeftButtonUp.On(this); Or better yet, just remove the variable declarations altogether:     var draggingEvents = from pos in Events.Mouse.Move.On(this)                              .SkipUntil(Events.Mouse.LeftButtonDown.On(this))                              .TakeUntil(Events.Mouse.LeftButtonUp.On(this))                              .Let(mm => mm.Zip(mm.Skip(1), (prev, cur) =>                                  new                                  {                                      X2 = cur.EventArgs.GetPosition(this).X,                                      X1 = prev.EventArgs.GetPosition(this).X,                                      Y2 = cur.EventArgs.GetPosition(this).Y,                                      Y1 = prev.EventArgs.GetPosition(this).Y                                  })).Repeat()                          select pos; The Move, LeftButtonDown and LeftButtonUp members of the Events.Mouse class are readonly instances of the ObservableEvent<TTarget, TEventArgs> class that provide type-safe access to the events via the On() method.  Here is the code for the class: using System; using System.Collections.Generic; using System.Linq;   namespace System.Linq {     /// <summary>     /// Represents an event that can be managed via the <see cref="Observable"/> API.     /// </summary>     /// <typeparam name="TTarget">The type of the target.</typeparam>     /// <typeparam name="TEventArgs">The type of the event args.</typeparam>     public class ObservableEvent<TTarget, TEventArgs> where TEventArgs : EventArgs     {         /// <summary>         /// Initializes a new instance of the <see cref="ObservableEvent"/> class.         /// </summary>         /// <param name="eventName">Name of the event.</param>         protected ObservableEvent(String eventName)         {             EventName = eventName;         }           /// <summary>         /// Registers the specified event name.         /// </summary>         /// <param name="eventName">Name of the event.</param>         /// <returns></returns>         public static ObservableEvent<TTarget, TEventArgs> Register(String eventName)         {             return new ObservableEvent<TTarget, TEventArgs>(eventName);         }           /// <summary>         /// Creates an enumerable sequence of event values for the specified target.         /// </summary>         /// <param name="target">The target.</param>         /// <returns></returns>         public IObservable<IEvent<TEventArgs>> On(TTarget target)         {             return Observable.FromEvent<TEventArgs>(target, EventName);         }           /// <summary>         /// Gets or sets the name of the event.         /// </summary>         /// <value>The name of the event.</value>         public string EventName { get; private set; }     } } And this is how it's used:     /// <summary>     /// Categorizes <see cref="ObservableEvents"/> by class and/or functionality.     /// </summary>     public static partial class Events     {         /// <summary>         /// Implements a set of predefined <see cref="ObservableEvent"/>s         /// for the <see cref="System.Windows.System.Windows.UIElement"/> class         /// that represent mouse related events.         /// </summary>         public static partial class Mouse         {             /// <summary>Represents the MouseMove event.</summary>             public static readonly ObservableEvent<UIElement, MouseEventArgs> Move =                 ObservableEvent<UIElement, MouseEventArgs>.Register("MouseMove");               // additional members omitted...         }     } The source code contains a static Events class with prefedined members for various categories (Key, Mouse, etc.).  There is also an Events.tt template that you can customize to generate additional event categories for any .NET type.  All you should have to do is add the name of your class to the types collection near the top of the template:     types = new Dictionary<String, Type>()     {         //{ "Microsoft.Maps.MapControl.Map, Microsoft.Maps.MapControl", null }         { "System.Windows.FrameworkElement, System.Windows", null },         { "Whiteboard.MainPage, Whiteboard", null }     }; The template is also a bit rough at this point, but at least it generates code that *should* compile.  Please let me know if you run into any issues with it.  Some people have reported errors when trying to use T4 templates within a Silverlight project, but I was able to get it to work with a little black magic...  You can download the source code for this project or play around with the live demo.  Just be warned that it is at a very early stage so don't expect to find much today.  I plan on adding alot more options like pen colors and sizes, saving, printing, etc. as time permits.  HINT: hold down the ESC key to erase! Enjoy! Additional Resources Using Reactive Extensions in Silverlight DevLabs: Reactive Extensions for .NET (Rx) Rx Framework Part III - LINQ to Events - Generating GetEventName() Wrapper Methods using T4

    Read the article

  • Time flies like an arrow demo in WinForms

    - by Benjol
    Looking at the Reactive Extensions for javascript demo on Jeff Van Gogh's blog, I thought I'd give it a try in C#/Winforms, but it doesn't seem to work so well. I just threw this into the constructor of a form (with the Rx framework installed and referenced): Observable.Context = SynchronizationContext.Current; var mousemove = Observable.FromEvent<MouseEventArgs>(this, "MouseMove"); var message = "Time flies like an arrow".ToCharArray(); for(int i = 0; i < message.Length; i++) { var l = new Label() { Text = message[i].ToString(), AutoSize = true, TextAlign = ContentAlignment.MiddleCenter }; int closure = i; mousemove .Delay(closure * 150) .Subscribe(e => { l.Left = e.EventArgs.X + closure * 15 + 10; l.Top = e.EventArgs.Y; //Debug.WriteLine(l.Text); }); Controls.Add(l); } When I move the mouse, the letters seem to get moved in a random order, and if I uncomment the Debug line, I see multiple events for the same letter... Any ideas? I've tried Throttle, but it doesn't seem to make any difference. Am I just asking too much of WinForms to move all those labels around? (Cross posted on Rx Forum)

    Read the article

  • Creating a mouse drag done observable with Reactive Extensions

    - by juharr
    I have the following var leftMouseDown = Observable.FromEvent<MouseButtonEventArgs>(displayCanvas, "MouseLeftButtonDown"); var leftMouseUp = Observable.FromEvent<MouseButtonEventArgs>(displayCanvas, "MouseLeftButtonUp"); var mouseMove = Observable.FromEvent<MouseEventArgs>(displayCanvas, "MouseMove"); var leftMouseDragging = from down in leftMouseDown let startPoint = down.EventArgs.GetPosition(displayCanvas) from move in mouseMove.TakeUntil(leftMouseUp) let endPoint = move.EventArgs.GetPosition(displayCanvas) select new { Start = startPoint, End = endPoint }; which when I subscribe to it will give me the start point of the drag and the current end point. Now I need to do something once the drag is done. I was unsuccessful in attempting to do this completely with RX and ended up doing leftMouseDragging.Subscribe(value=> { dragging = true; //Some other code }); leftMouseUp.Subscribe(e=> { if(dragging) { MessageBox.Show("Just finished dragging"); dragging = false; } }); This works fine until I do a right mouse button drag. Then when I click the left mouse button I get the message box. If I only do a left button drag I get the message box, and then clicking the left mouse button doesn't produce the box. I'd like to do this without the external state, but if nothing else I'd at least like for it to work properly. FYI: I tried making dragging volatile and using a lock, but that didn't work. EDIT It turns out my problem was with a right click context menu. Once I got rid of that my above code worked. So, now my problem is how to I get to have the context menu and still have my code work. I assume the Context menu was handling the left mouse click and that somehow caused my code to not work, but I'm still puzzling it out.

    Read the article

  • Division of text follow the cursor via Javascript/Jquery

    - by webzide
    Dear experts, I wanted have a dynamic division of content follow you with the cursor in the web browser space. I am not a pro at JS so I spent 2 hours to finally debugged a very stupid way to accomplish this. $(document).ready(function () { function func(evt) { var evt = (evt) ? evt : event; var div = document.createElement('div'); div.style.position = "absolute"; div.style.left = evt.clientX + "px"; div.style.top = evt.clientY + "px"; $(div).attr("id", "current") div.innerHTML = "CURSOR FOLLOW TEXT"; $(this).append($(div)); $(this).unbind() $(this).bind('mousemove', function () { $('div').remove("#current"); }); $(this).bind('mousemove', func); } $("body").bind('mousemove', func) }); As you can see this is pretty much Brute force and it slows down the browser quite a bit. I often experience a lag on the browser as a drag my mouse from one place to another. Is there a way to accomplish this easier and faster and more intuitive. I know you can use the cursor image technique but thats something I'm looking to avoid. Thanks in advance.

    Read the article

  • Click at specified client area

    - by VixinG
    Click doesn't work - I don't know why and can't find a solution :( ie. Click(150,215) should move mouse to the client area and click there. [DllImport("user32.dll")] private static extern bool ScreenToClient(IntPtr hWnd, ref Point lpPoint); [DllImport("user32", SetLastError = true)] private static extern int SetCursorPos(int x, int y); static void MouseMove(int x, int y) { Point p = new Point(x * -1, y * -1); ScreenToClient(hWnd, ref p); p = new Point(p.X * -1, p.Y * -1); SetCursorPos(p.X, p.Y); } static void Click(int x, int y) { MouseMove(x, y); SendMessage(hWnd, WM_LBUTTONDOWN, (IntPtr)0x1, new IntPtr(y * 0x10000 + x)); SendMessage(hWnd, WM_LBUTTONUP, (IntPtr)0x1, new IntPtr(y * 0x10000 + x)); } Edit: Of course I can use mouse_event for that, but I would like to see a solution for SendMessage()... [DllImport("user32.dll")] static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); const int LEFTDOWN = 0x00000002; const int LEFTUP = 0x00000004; static void Click(int x, int y) { MouseMove(x, y); mouse_event((int)(LEFTDOWN), 0, 0, 0, 0); mouse_event((int)(LEFTUP), 0, 0, 0, 0); }

    Read the article

  • WebTextEdit ClientSideEvent Javascript - Can't Eval

    - by ismail
    Hi, I urgently need help, please. WebtextEdit ClientSideEvent execute javascript statement on mousemove event. I can successfully change the style of another object type on this WebTextEdit ClientSide MouseMove event: document.getElementById("Object2").style.backgroundColor = '#F0F5F7'; But when I want to change the style of the WebTextEdit control: document.getElementById("WebTextEdit1").style.backgroundColor = '#F0F5F7'; Then nothing happens. When I execute the script on the same WebTextEdit Clientside for another object which is not a WebtextEdit: Object2.style.border='1px solid #FFE6A0'; Then it works. But when I want to change the WebtextEdit Clientside style: WebTextEdit1.style.border='1px solid #FFE6A0'; Then I get Error: Can't Eval WebTextEdit1.style.border='1px solid #FFE6A0';

    Read the article

  • jquery - deciding whether a user is "away"

    - by Phil Jackson
    hi, im doing a little test to check whether the user is "away" (unactive) or not; function away_status(){ $("#away_stat_update").everyTime(1000, function(i) { var number = Number($(this).html()); if( number == 20 ) { // set user as away alert( "user away" ); } if( number > 20 ) { $("*").mousemove(function(e){ $("#away_stat_update").html(0); var number = Number(0); // reset user to being online alert( "user back online" ); }); } $("#away_stat_update").html( number + 1 ); }); $("*").mousemove(function(e){ $("#away_stat_update").html(0); }); } away_status(); the only problem is that when the number is greater than 20 and the mouse is moved it keeps alerting "user back on line" instead of doing it just once. The number is resetting by the way.

    Read the article

  • Mouse down Issue

    - by 3gwebtrain
    HI, I am making my own scroll bar. in which i made this code below i pasted. i am getting the issue from this code. i) in the first time i am pressing "#scroller" that works fine. ii) in case of second or other time when i am enter into "#scroller" itself, i am getting the alert "hi", instead of i am pressing the "#scroller", i know that i am doing some wrong this with my code, but i unable to find the mistake. Any one help me? $(function(){ var slidesWidth = ($('#show-content li').length)*($('#show-content li').width()+20); $('#show-content ul').width(slidesWidth); var scrollBarWidth = (100/slidesWidth)*1000;//presently taken by manual/ $('#scroller').width(scrollBarWidth); $('#scroller').bind('mousedown',function(){ $('#scroller').mousemove(function(){ alert('hi'); }) }) $('#scroller').bind('mouseup',function(){ $('#scroller').unbind('mousedown,mousemove'); alert('unbinded'); }) })

    Read the article

  • Can I control the mouse cursor from within R?

    - by Bernd Meyer
    Is it possible, to control the mouse pointer from the R console? I have something like this in mind: move_mouse(x_pos=100,y_pos=200) # move the mouse pointer to position (100,200) mouse_left_button_down # simulate a press of the left button move_mouse(x_pos=120,y_pos=250) # move mouse to select something mose_release_left_button # release the pressed button In MATLAB, something like this is possible with the following code import java.awt.Robot; mouse = Robot; mouse.mouseMove(0, 0); mouse.mouseMove(100, 200); Is something similar possible for the keybord? E.g. simulate keybord events?

    Read the article

  • Simple Mouse Move Event in F# with Winforms

    - by MarkPearl
    This evening I had the pleasure of reading one of ThomasP’s blog posts on first class events. It was an excellent read, and I thought I would make a brief derivative of his post to explore some of the basics. In Thomas’s post he has a form with an ellipse on it that when he clicks on the ellipse it pops up a message box with the button clicked… awesome. Something that got me on the post though was the code similar to the one below… // React to Mouse Move events on the form let evtMessages = frm.MouseMove |> Event.map (fun mi -> mi.Location.ToString()) |> Event.map (sprintf "Hey, you clicked on the ellipse.\nUsing: %s") |> Event.add (MessageBox.Show >> ignore) The MessageBox is a function with a string passed into it. What if I wanted to rather change a mutable value holder instead, how would the syntax go for that? Immediately the thought came to me of anonymous functions. I’ve used them before to do something like this… let HelloPerson personName = "Hello " + personName |> fun(x) -> Console.WriteLine(x) So using the same approach I adapted the event code to instead of showing a Message Box with a string passed in to it, to rather change the forms header. |> Event.map (sprintf "Your mouse position is %s") |> Event.add(fun(x) -> frm.Text <- x) Okay… it looks a bit weird with the –> x <- syntax, but makes sense and works… The next thing I wanted to do was change Thomas’s code sample from having an ellipse, and reacting to the position of the mouse and click, to rather trigger the event whenever the mouse moved. This simple involved removing some filtering code. Finally I wanted the code to work as a FSharp Project without having to run through the F# interactive. To achieve this I just needed to find out how to trigger the window event loop. This can be achieved with the code below… // Program eventloop while frm.Created do Application.DoEvents()   So lets look at the complete code sample… #light open System open System.Drawing open System.Windows.Forms // Create the main form let frm = new Form(ClientSize=Size(600,400)) // React to Mouse Move events on the form let evtMessages = frm.MouseMove |> Event.map (fun mi -> mi.Location.ToString()) |> Event.map (sprintf "Your mouse position is %s") |> Event.add(fun(x) -> frm.Text <- x) // Show the form frm.Show() // Program eventloop while frm.Created do Application.DoEvents()

    Read the article

  • Multi-touch capabilities for Ubuntu 12.04? How can I configure the system to support it?

    - by dd dong
    I installed Ubuntu 13.10, it supports default multi-touch perfectly! I need Ubuntu 12.04, however, it does not appear to support multi-touch features. I write a touch test program, it supports touch and mouseMove at the same time, but I just need touch function. I know we can set the device to grab bits. But how can I configure the system to support it? It gives me an error when I try to use multi-touch.

    Read the article

  • .NET Programmatically invoke screenclick doesn't work?

    - by ropstah
    I'm trying to programmatically invoke an onclick event however the click is not received/handled. Am I missing something, or is security preventing the click to be executed? I have a forms application which is invisible. Basically I would like to say: DoDoubleClick(wait, x, y) This should raise two click (mousedown+mouseup) events on screen with the specified wait interval. However the click isn't received in a Flash application in Firefox (which is running at that moment). Here's my code: Form: Public Class Form1 Private WithEvents gmh As GlobalMouseHook Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load gmh = New GlobalMouseHook() Me.Visible = false gmh.DoDoubleClick(50, 800, 600) End Sub Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed gmh.Dispose() End Sub Private Sub gmh_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gmh.MouseDown End Sub Private Sub gmh_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gmh.MouseMove End Sub Private Sub gmh_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gmh.MouseUp End Sub End Class GlobalMouseHook class: Friend Class GlobalMouseHook Implements IDisposable Private hhk As IntPtr = IntPtr.Zero Private disposedValue As Boolean = False Public Event MouseDown As MouseEventHandler Public Event MouseUp As MouseEventHandler Public Event MouseMove As MouseEventHandler Public Sub New() Hook() End Sub Private Sub Hook() Dim hInstance As IntPtr = LoadLibrary("User32") hhk = SetWindowsHookEx(WH_MOUSE_LL, AddressOf Me.HookProc, hInstance, 0) End Sub Private Sub Unhook() UnhookWindowsHookEx(hhk) End Sub Public Sub DoDoubleClick(ByVal wait As Integer, ByVal x As Integer, ByVal y As Integer) RaiseEvent MouseDown(Me, New MouseEventArgs(MouseButtons.Left, 1, x, y, 0)) RaiseEvent MouseUp(Me, Nothing) System.Threading.Thread.Sleep(wait) RaiseEvent MouseDown(Me, New MouseEventArgs(MouseButtons.Left, 1, x, y, 0)) RaiseEvent MouseUp(Me, Nothing) End Sub Private Function HookProc(ByVal nCode As Integer, ByVal wParam As UInteger, ByRef lParam As MSLLHOOKSTRUCT) As Integer If nCode >= 0 Then Select Case wParam Case WM_LBUTTONDOWN RaiseEvent MouseDown(Me, New MouseEventArgs(MouseButtons.Left, 0, lParam.pt.x, lParam.pt.y, 0)) Case WM_RBUTTONDOWN RaiseEvent MouseDown(Me, New MouseEventArgs(MouseButtons.Right, 0, lParam.pt.x, lParam.pt.y, 0)) Case WM_MBUTTONDOWN RaiseEvent MouseDown(Me, New MouseEventArgs(MouseButtons.Middle, 0, lParam.pt.x, lParam.pt.y, 0)) Case WM_LBUTTONUP, WM_RBUTTONUP, WM_MBUTTONUP RaiseEvent MouseUp(Nothing, Nothing) Case WM_MOUSEMOVE RaiseEvent MouseMove(Nothing, Nothing) Case WM_MOUSEWHEEL, WM_MOUSEHWHEEL Case Else Console.WriteLine(wParam) End Select End If Return CallNextHookEx(hhk, nCode, wParam, lParam) End Function Private Structure API_POINT Public x As Integer Public y As Integer End Structure Private Structure MSLLHOOKSTRUCT Public pt As API_POINT Public mouseData As UInteger Public flags As UInteger Public time As UInteger Public dwExtraInfo As IntPtr End Structure Private Const WM_MOUSEWHEEL As UInteger = &H20A Private Const WM_MOUSEHWHEEL As UInteger = &H20E Private Const WM_MOUSEMOVE As UInteger = &H200 Private Const WM_LBUTTONDOWN As UInteger = &H201 Private Const WM_LBUTTONUP As UInteger = &H202 Private Const WM_MBUTTONDOWN As UInteger = &H207 Private Const WM_MBUTTONUP As UInteger = &H208 Private Const WM_RBUTTONDOWN As UInteger = &H204 Private Const WM_RBUTTONUP As UInteger = &H205 Private Const WH_MOUSE_LL As Integer = 14 Private Delegate Function LowLevelMouseHookProc(ByVal nCode As Integer, ByVal wParam As UInteger, ByRef lParam As MSLLHOOKSTRUCT) As Integer Private Declare Auto Function LoadLibrary Lib "kernel32" (ByVal lpFileName As String) As IntPtr Private Declare Auto Function SetWindowsHookEx Lib "user32.dll" (ByVal idHook As Integer, ByVal lpfn As LowLevelMouseHookProc, ByVal hInstance As IntPtr, ByVal dwThreadId As UInteger) As IntPtr Private Declare Function CallNextHookEx Lib "user32" (ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As UInteger, ByRef lParam As MSLLHOOKSTRUCT) As Integer Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hhk As IntPtr) As Boolean ' IDisposable Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not Me.disposedValue Then If disposing Then ' TODO: free other state (managed objects). End If Unhook() End If Me.disposedValue = True End Sub ' This code added by Visual Basic to correctly implement the disposablepattern. Public Sub Dispose() Implements IDisposable.Dispose ' Do not change this code. Put cleanup code in Dispose(ByValdisposing As Boolean) above. Dispose(True) GC.SuppressFinalize(Me) End Sub End Class

    Read the article

  • Firefox drags div like it was an image, javascript event handlers possibly to blame

    - by user281434
    Hi, I'm using this HTML,CSS and Javascript code (in one document together if you want to test it out): <style type="text/css"> #slider_container { width: 200px; height: 30px; background-color: red; display:block; } #slider { width: 20px; height: 30px; background-color: blue; display:block; position:absolute; left:0; } </style> <script type="text/javascript" src="../../js/libs/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#slider").mousedown(function() { $(document).mousemove(function(evnt) { $("#test").html("sliding"); }).mouseup(function() { $("#test").html("not sliding"); $(document).unbind("mousemove mouseup"); });}); }); </script> <div id="test">a</div> <div id="slider_container"> <div id="slider"></div> </div> Everything (surprisingly) works fine in IE, but firefox seems to totally clusterf*ck when this javascript is used. The first "slide" is okay, you drag, it says "sliding", you drop, it says "not sliding". On the second "slide" (or mousedown if you will), firefox suddenly thinks the div is an image or link and wants to drag it around. Screenshot of the dragging: http://i.imgur.com/nPJxZ.jpg Obviously the blue div half-positioned in the red div is the one being dragged. Windows does not capture the cursor when you take a screenshot, but it's a stop sign. Is there someway to prevent this default behaviour?

    Read the article

  • (solved) jQuery click and drag/scroll window: jagged movement

    - by Josh
    Edit: derp, using pageX/Y instead of clientX/Y -- apparently scrollBy expects input with that offset rather than the other. Jaggy movement gone. I am getting jagged movement when doing small scroll increments using the following bindings. Can anyone point me in the right direction for how to smooth this out? FYI, its intermittent. It seems like, if I click and hold for a second, then drag at a decent speed there are no problems. Edit: What the hell? I get this output on debug... obvious jog backwards and forwards. This will happen in succession and seems to have no correlation with the mouse, other than the mouse is moving. x 398 : 403 y 374 : 377 x 403 : 399 y 377 : 374 x 399 : 404 y 374 : 377 Josh sococo.client.panMap = function(e){ e.preventDefault(); var movex = sococo.client.currX - e.pageX ; var movey = sococo.client.currY - e.pageY; console.log( sococo.client.currX +" : " + e.pageX ); window.scrollBy(movex,movey); sococo.client.currY = e.pageY; sococo.client.currX = e.pageX; } $(document).mousedown( function(e){ e.preventDefault(); sococo.client.currX = e.pageX; sococo.client.currY = e.pageY; $(document).bind( "mousemove", sococo.client.panMap ); }); $(document).mouseup( function(e){ e.preventDefault(); $(document).unbind( "mousemove", sococo.client.panMap ); });

    Read the article

  • TranslateTransform for drag and drop in Silverlight

    - by fuzzyman
    We're trying to implement drag and drop in Silverlight (3). We want users to be able to drag elements from a treeview onto another part of a UI. The parent element is a Grid, and we've been trying to use a TranslateTransform along with the MouseLeftButtonDown, MouseMove (etc) events, as recommended by various online examples. For example: http://www.85turns.com/2008/08/13/drag-and-drop-silverlight-example/ We're doing this in IronPython, but that should be more or less irrelevant. The drag start is correctly initiated, but the item we are dragging appears in the 'wrong' location (offset a few hundred pixels to the right and down from the cursor) and I can't for the life of me work out why. Basic xaml: <Grid x:Name="layout_root"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="120"/> </Grid.RowDefinitions> <Border x:Name="drag" Background="LightGray" Width="40" Height="15" Visibility="Collapsed" Canvas.ZIndex="10"> <Border.RenderTransform> <TranslateTransform x:Name="transform" X="0" Y="0" /> </Border.RenderTransform> <TextBlock x:Name="dragText" TextAlignment="Center" Foreground="Gray" Text="foo" /> </Border> ... </Grid> The startDrag method is triggered by the MouseLeftButtonDown event (on a TextBlock in a TreeViewItem.Header). onDrag is triggered by MouseMove. In the following code self.root is Application.Current.RootVisual (top level UI element from app.xaml): def startDrag(self, sender, event): self.root.drag.Visibility = Visibility.Visible self.root.dragText.Text = sender.Text position = event.GetPosition(self.root.drag.Parent) self.root.drag.transform.X = position.X self.root.drag.transform.Y = position.Y self.root.CaptureMouse() self._captured = True def onDrag(self, sender, event): if self._captured: position = event.GetPosition(self.root.drag.Parent) self.root.drag.transform.X = position.X self.root.drag.transform.Y = position.Y The dragged item follows the mouse move, but is offset considerably. Any idea what I am doing wrong and how to correct it?

    Read the article

  • C# override WndProc in Control level to detect

    - by Nullstr1ng
    I have overridden WndProc in UserControl level to detect MouseDown, MouseUp, and MouseMove to any Control added in that UserControl. protected override void WndProc(ref Message m) { Point mouseLoc = new Point(); switch (m.Msg) { case WM_LBUTTONDOWN: System.Diagnostics.Debug.WriteLine("mouse down"); //this.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, mouseLoc.X, mouseLoc.Y, 0)); break; case WM_LBUTTONUP: System.Diagnostics.Debug.WriteLine("mouse up"); //this.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, mouseLoc.X,mouseLoc.Y, 0)); break; case WM_MOUSEMOVE: int lParam = m.LParam.ToInt32(); //mouseLoc.X = lParam & 0xFFFF; //mouseLoc.Y = (int)(lParam & 0xFFFF0000 >> 16); mouseLoc.X = (Int16)m.LParam; mouseLoc.Y = (Int16)((int)m.LParam >> 16); System.Diagnostics.Debug.WriteLine("mouse move: " + mouseLoc.X + ", " + mouseLoc.Y); //this.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, mouseLoc.X,mouseLoc.Y, 0)); break; } base.WndProc(ref m); } MouseMove, Down, and Up are working when the mouse pointer is in UserControl but when the mouse pointer is on other control (inside my UserControl) it doesn't work. Am I doing something wrong? Currently developing a flick and scroll control.

    Read the article

  • Detecting whether user stayed after prompting onBeforeUnload

    - by Daniel Magliola
    In a web app I'm working on, I'm capturing onBeforeUnload to ask the user whether he really wants to exit. Now, if he decides to stay, there are a number of things I'd like to do. What I'm trying to figure out is that he actually chose to stay. I can of course declare a SetTimeout for "x" seconds, and if that fires, then it would mean the user is still there (because we didn't get unloaded). The problem is that the user can take any time to decide whether to stay or not... I was first hoping that while the dialog was showing, SetTimeout calls would not fire, so I could set a timeout for a short time and it'd only fire if the user chose to stay. However, timeouts do fire while the dialog is shown, so that doesn't work. Another idea I tried is capturing mouseMoves on the window/document. While the dialog is shown, mouseMoves indeed don't fire, except for one weird exception that really applies to my case, so that won't work either. Can anyone think of other way to do this? Thanks! (In case you're curious, the reason capturing mouseMove doesn't work is that I have an IFrame in my page, containing a site from another domain. If at the time of unloading the page, the focus is within the IFrame, while the dialog shows, then I get the MouseMove event firing ONCE when the mouse moves from inside the IFrame to the outside (at least in Firefox). That's probably a bug, but still, it's very likely that'll happen in our case, so I can't use this method).

    Read the article

  • wpf: capturing mouse does not work

    - by amethyste
    hello I am developing an kind of outlook calendar application where I need to make the appointment resizable from mouse. My first try with a thumb did not work properly so I tried another way. What I did is that: 1) on the botton of the appointmennt panel I added a rectangle to figure out the resize zone (the thumb). The appointment panel is put on a grid panel. 2) I intercept down event on the rectangle and send event to this code: private Point startPoint; private void OnResizeElementMouseDown(object sender, MouseButtonEventArgs e) { e.Handled = true; this.MouseMove += new MouseEventHandler(ResizeEndElement_MouseMove); this.MouseLeftButtonUp += new MouseButtonEventHandler(OnResizeElementMouseUp); // some code to perform new height computation Mouse.Capture(this); } where this is the appointment panel that own the thumb. Decreasing height works well. But increasing is more difficult. If I move the mouse very very slowly it's OK, if I speed it up a little bit it tends to leave out the appointment panel and then all MouseMove event are lost. I thought Mouse.Capture() was propose to solve this kind of problem, but in fact not. Does anybody know what is wrong in my code?

    Read the article

  • Make an element visible to the user but invisible to events

    - by Acorn
    I'm not quite sure how to describe what I'm looking to do, but I'll do my best. At the moment I have a parent <div>, with absolutely positioned child <div>s within it, and I'm tracking the mouse pointer location coordinates relative to the element your mouse is over. At the moment, when I mouse over my child <div>s, I get the mouse location relative to them, but I want the coordinates to be relative the the parent <div> even when mousing over the child elements. So I basically want the child elements to be visible, but transparent to the mousemove, so I want the mousemove to go straight through to the parent element. How would I do this? Do I maybe need to somehow make the parent <div> be in the forground but still have the child <div>s show through? or make a transparent <div> overlay just to get the mouse coordinates? Here's a link to the page I'm experimenting on: http://acorn.host22.com/mouse.html

    Read the article

  • Stop Observing Events with JS Prototype not working with .bind(this)

    - by PeterBelm
    I'm working on a Javascript class based on the Prototype library. This class needs to observe an event to perform a drag operation (the current drag-drop controls aren't right for this situation), but I'm having problems making it stop observing the events. Here's a sample that causes this problem: var TestClass = Class.create({ initialize: function(element) { this.element = element; Event.observe(element, 'mousedown', function() { Event.observe(window, 'mousemove', this.updateDrag.bind(this)); Event.observe(window, 'mouseup', this.stopDrag.bind(this)); }); }, updateDrag: function(event) { var x = Event.pointerX(event); var y = Event.pointerY(event); this.element.style.top = y + 'px'; this.element.style.left = x + 'px'; }, stopDrag: function(event) { console.log("stopping drag"); Event.stopObserving(window, 'mousemove', this.updateDrag.bind(this)); Event.stopObserving(window, 'mouseup', this.stopDrag.bind(this)); } }); Without .bind(this) then this.element is undefined, but with it the events don't stop being observed (the console output does occur though).

    Read the article

  • Selenium Webdriver Java - looking for alternatives for Actions and Robot when performing drag-and-drop

    - by Ja-ke Alconcel
    I first tried Actions class and the drag-and-drop does work on different elements, however it was unable to locate the a specific draggable element on it's exact screen/webpage position. Here's the code I've used: Point loc = driver.findElement(By.id("thiselement")).getLocation(); System.out.println(loc); WebElement drag = driver.findElement(By.id("thiselement")); Actions test = new Actions(driver); test.dragAndDropBy(drag, 0, 60).build().perform(); I checked the element with it's pixel location and it prints (837, -52), which was somewhere on top of the webpage and was pixels away from the actual element. Then I tried using the Robot class and works perfectly fine on my script, but can only provide constant successful runs on a single test machine, running it with a different machine with different screen resolution and screen size will render the script to fail due to the dependency of Robot on the pixel location of the element. The sample code of the Robot script I'm using: Robot dragAndDrop = new Robot(); dragAndDrop.mouseMove(945, 166); //actual pixel location of the draggable element dragAndDrop.mousePress(InputEvent.BUTTON1_MASK); sleep(3000); dragAndDrop.mouseMove(945, 226); dragAndDrop.mouseRelease(InputEvent.BUTTON1_MASK); sleep(3000); Is there any alternative for Actions and Robot to automate drag-and-drop? Or maybe a help on working the script to work on Actions as I really can't use Robot. Thanks in advance.

    Read the article

  • A rectangle drawn with DrawingContext.DrawRectangle blocks mouse

    - by dharmatech
    The WPF program below puts up a window which looks like this: Mouse-movement outside the black square causes the window title to be updated with the mouse's position. The updating stops when the mouse enters the square. I'd like for MouseMove to continue to trigger even when the mouse is over the square. Is there a way to do this? using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace Wpf_Particle_Demo { class DrawingVisualElement : FrameworkElement { public DrawingVisual visual; public DrawingVisualElement() { visual = new DrawingVisual(); } protected override int VisualChildrenCount { get { return 1; } } protected override Visual GetVisualChild(int index) { return visual; } } public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var canvas = new Canvas(); Content = canvas; var element = new DrawingVisualElement(); canvas.Children.Add(element); CompositionTarget.Rendering += (s, e) => { using (var dc = element.visual.RenderOpen()) dc.DrawRectangle(Brushes.Black, null, new Rect(0, 0, 50, 50)); }; MouseMove += (s, e) => Title = e.GetPosition(canvas).ToString(); } } }

    Read the article

  • jQuery - Moving background arrow in menu

    - by B M
    I would expect something like this to be pretty popular in demand but I had much trouble finding a suiting script. I've got a basic menu build like this: <div id="menu"> <ul> <li><a href="#"><img src="images/btn1.png"></a></li> <li><a href="#"><img src="images/btn2.png"></a></li> <li><a href="#"><img src="images/btn3.png"></a></li> </ul> </div> The div #menu has a background image of a small arrow. I want the arrow to move vertically in front of the corresponding menu image when you mouseover/mousemove the whole #menu div. Also when one of the menu images has been clicked the arrow should stay in it's position in front of the corresponding menu image. I started something but I notice it's going downwards, since it's only working when you're at the top of the page. What I have is this: $('#menu').css({backgroundPosition: '5px 10px'}); //Starting position $('#menu').mousemove(function(e){ $('#menu').stop().animate( {backgroundPosition: '5px ' + (e.pageY-60) + ' px'}, {duration:100} ) }).mouseout(function(){ $('#menu').stop().animate( {backgroundPosition: '5px 10px'}, {duration:100} ) }); Please help! ps. I'm using this plugin to move background images smoothly.

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >