Perform a function till mouse is pressed down - c#

I want to how to implement this
Till i press the mouse button down i want some code to execute. The problem is I used mouse Down event but it works like a mouse click event.
Can you please help.

Create 2 functions, one to start your code to execute, and one to stop it.
Call the start on a mouseDown event, and call the stop on mouseUp.
Unless I don't understand what you're trying to do, that should be the way to go.

Related

Unity Cursor missing, can't click buttons

I'm making a Game right now, I have a problem with the main menu. When I press ESC, the menu opens and the time freezes. The cursor is then visible. But I can still look around, while the menu is on the screen. And if I click a button, for example the resume button, nothing happens.
If the buttons don't do anything, make sure to asign a task for each button, for example, if you want to pause the game when the player press the pause button, make sure that the pause button has the task of pausing the game asigned to it.
I think that your problem is with the Event System of your scene, the Canvas needs an event system to work properly, if you delete it or change something in the event system, the Canvas will not work.
The Event System is created automatically when you add a canvas into your scene, make sure it looks like that:

C# Mouse Click speed

Is it possible to remove the limit for the Mouse Click speed in C#?
Im trying to make a Click Game Programm. You have 15 seconds time to click on a Panel as fast as you can. Every click is a Point.
The Problem is... As example, when i click 10 times per second, I only get 5-6 Points per seconds and so I can't click as fast as I can.
Has somebody an idea to bypass this?
Thanks
When you subscribe to the Click event, you will not see second clicks that occur in the doubleclick treshold, those are propagated to the DoubleClick event handler.
If you want to register clicks and bypass double click detection, subscribe to the MouseDown event instead.

How can i detect if the mouse is moving both within and out of the bounds of my window in WPF/C#?

I have a small video app that i would like to give vlc-like functionality. By that, I mean having a certain element disappear and appear on mouse move or mouse not moving. I have a rough concept of how to do this but I have no ideea how i coul detect if the mouse is moving or not. I thought about using the GetPosition function but that will just give me the mouse's position and won't let me know if the cursor is moving or not. I would like to use a timer to count down 2-3 seconds after the mouse has stopped moving and then either fade out the control or just make it collapse without further ado. I can't check the value of the position variable every milisecond. Is there some other way to do this ?
You can use a hook functionality so you will be notified when a mouse move, I use to use this free opensource library.
How to use it:
using Gma.UserActivityMonitor.GlobalEventProvider;
GlobalEventProvider _globalEventProvider1
= new Gma.UserActivityMonitor.GlobalEventProvider();
this.globalEventProvider1.MouseMove += HookMouseMove;//to listen to mouse move
Capture the mouse. Release the capture if the user actually clicks anywhere else. Then you can use the standard WPF mouse move event.
myElement.MouseMove += (my MouseMove handler)
Mouse.Capture(myElement);

C# MouseClick Event a bit laggy, how can I fix this?

I'm making a craps game, and I have a "Craps Table" image in a PictureBox Control.
I've made a MouseClick event handler for the PictureBox to check what region was selected by the user, and add a bet to that "Part of the Craps Table" when clicked.
Everything works great, except if I click the region very quickly, the event fires only once for every two clicks (Approx).
I've searched everywhere, and not quite sure what I'm doing wrong. I thought at first it might be a graphics problem, but I've ruled just about everything out, and I'm thinking that the event simply isn't firing properly at high click speeds, I have to pause for half a second between clicks for it to fire.
Thanks for any advice..
Also guessing, Try MouseDown instead of MouseClick...
Another thing to check: If your app is high-cpu intensive, and the UI thread is mostly busy, the mouse events will arrive late.
My guess is that by clicking very quickly, you're triggering the doubleclick event instead of click

How to detect more than one keypress simultaneously in C#?

I am working on a map editor for my game and I use the arrow keys to scroll around the map area. Currently I'm using the KeyDown event, which works fine for scrolling up, down, left or right - but my question would be how to allow diagonal scrolling. Currently, if I hold the right-arrow and then (whilst keeping the right-arrow held) I then press and hold the down-arrow, the down direction replaces the scrolling to the right instead of scrolling diagonally to the bottom right.
Is there a way, for instance, that I could check whether another arrow key is being pressed whilst in the KeyDown event? How can I respond to more than one key being held?
Thanks
Not easily, the key-down of the 2nd keystroke stops the 1st one from repeating. What you have to do is record that the key is down in the KeyDown event. Cancel that state in the KeyUp event. Next, use a Timer (~250 msec) and in its Tick event check the state of the keys.
The easiest way to do this is to use a Windows API call to get the state of every key on they keyboard, and then check the keys you are interested in: GetKeyboardState via PInvoke.
You can call it on KeyDown/KeyUp, check the state of the keyboard, and act appropriately.

Categories

Resources