action script 3 - is it possible to simulate pressure on mouse down - actionscript-3

I was wondering if is there is possible to detect the pressure (how hard the mouse button is pressed and kept hold) on mouse? If not, can we simulate it by some technique/method?

There is no way to detect the amount of pressure applied to the mouse button or pad for that matter.
IMO the best way to simulate this effect would be to work with some kind of timer - where you log the time from mouseDown to mouseUp and calculate what this means in terms of pressure. To help the user i would make some kind of graphical indication as the pressure is mounting (ie time is spent holding the mouse button down)

No way, you cannot detect how hard the button was pressed.
Keep in mind that the mouse is a digital input, that means that when you click it you're pressing a switch that only has two states (ON/OFF). No pressure amount info sent to the computer. It's not a limit of Flash, it's a limit of the input device. Try open a mouse and you'll see the switches below the mouse buttons.
But as #Dennis Flood said, you can use a timer to calculate how long it was pressed (on mouse down start a timer, then on mouse up stop the timer and calculate the time).
I dunno if you have some experience with Arduino, but I would use it if you're working on an off-line sytem (like an installation). You could use some analog pressure sensors instead of your mouse and send the values to flash.

Related

How application get mouse movement when using pyautogui

When I move mouse without pyautogui pass by a application, for example windows calculator, button of calculator will change it's color. It seems that, calculator captured the movement of my mouse.
Like this, you can see button 9 color changed to gray:
But when I use pyautogui, invoke pyautogui.moveTo function. I can see the mouse cursor move to the correct location, but button 9's color keep white.
I'm sure that the x,y possion pass to function pyautogui.moveTo is correct. If I invoke pyautogui.click(), number 9 is showed on calculator.
Is there any way to ensure that application recognize the movement triggered by pyautogui?
Thank you
Well Although I don't really see a problem here if it bugs you that much try to use the third argument for the moveTo() function.
>>> pyautogui.moveTo(100, 200, 2) # moves mouse to X of 100, Y of 200 over 2 seconds
Here it will slide over slowly in two seconds and will give the hover effect.
If the duration is less than pyautogui.MINIMUM_DURATION the movement will be instant. By default, pyautogui.MINIMUM_DURATION is 0.1.
Hope this helps.

New HTML5 canvas method: addHitRegion

I've been reading a bit about the forthcoming addHitRegion() method for canvas. From what I've read it sounds much like a way to add clickable hotspots to your canvas - is this correct?
I never heard of that before, but it seems clickable hotspots are one of the possible uses.
From the current specs:
Hit regions can be used for a variety of purposes:
With an ID, they can make hit detection easier by having the user agent check which region the mouse is over and include the ID in the mouse events.
With a control, they can make routing events to DOM elements automatic, allowing e.g. clicks on a canvas to automatically submit a form via a button element.
With a label, they can make it easier for users to explore a canvas without seeing it, e.g. by touch on a mobile device.
With a cursor, they can make it easier for different regions of the canvas to have different cursors, with the user agent automatically switching between them.

Flash Expandable Banner - Detect Mouse Leave

I have created an expandable banner ad in Flash. Everything is great except one thing. How can I detect when the user is no longer hovering over the flash ad? I have tried to ad a "hit area" which can be used to detect MOUSE_OUT. The issue is, there is a video playing, as well as social media buttons which need to be clickable. If I place a hit area over these, they are no longer clickable. If I place the hit area behind the buttons, the MOUSE_OUT event triggers when you hover over the button.
What is the best practice for a scenario such as this? I have also tried detecting MOUSE_LEAVE on the stage object, but this doesn't seem to function correctly once deployed on an HTML page. Thanks for the assistance.
You can try adding an ENTER_FRAME event that constantly checks stage.mouseX and stage.mouseY. These values should report correctly while the mouse is on the Flash content, and will report the last known mouse coordinates when the mouse is no longer on the stage. However, the last known mouse coordinates may not always be the actual width or height of the stage, so you probably want to add some tolerance in there.
For instance, if your (expanded) Flash content width is 500px, in the ENTER_FRAME event you can check if stage.mouseX is less than 10px (mouse moving off to the left) or more than 490px (mouse is moving off to the right) and minimize the Flash content. Repeat for the height, and adjust tolerance values as needed.
This should give you the effect you want. The only downside that I can see is the overhead of the ENTER_FRAME event just to check whether the mouse has left the content, but I don't see any way around that.

Key press issue in ActionScript 3

I'm creating a DDR-like game for an assignment and my keyboard seems to respond and trace it, but only if I press on the screen with the mouse first.
How can I get rid of that and just have it respond right away?
right_mc is the arrow that's moving
ArrowRight_mc is the arrow at the top
perfect_mc should pop up briefly
and so should a glowing arrow where it hits.
Here is what I have so far:
if(rightDown){
trace("right arrow");
if(right_mc){
if(right_mc.y >= ArrowRight_mc.y){
perfect_mc.visible = true;
glowRight_mc.visible = true;
}
}
}
This has been a long standing issue for Flash developers. Flash needs keyboard focus before it can detect keyboard events.
The problem is that the browser does not give focus to the SWF until the user clicks somewhere inside the SWF. This does make sense though. I don't want the web page I am on to lose focus just because there is a flash movie embedded somewhere. This is a security feature, to stop things like Flash banner ads being silent key loggers. However there are some instances that it makes sense to force the focus e.g. a Flash game where its the only thing on the HTML page.
Usually the best thing to do is have start menu screen with a "play" button. This forces the user to click on the SWF without even knowing about this "focus issue".
There is more info at the Adobe Technote - Giving keyboard focus to an embedded Flash movie.
***EDIT****
Whether the Flash has focus or not, only affects keyboard events. It will not affect code from running, movieclips from playing, or sounds/video from playing.
The issue here is that the embedded SWF file does not have focus when the screen first loads. You can assign focus to it using JavaScript but in my experience, this does not always work 100% of the time because of variations in the way browsers interpret JS. What a lot of people do is have a big START button following the load of the game so that players have to click on the SWF to begin playing. Some sites, even use JS to detect when the game has lost focus and will pause the game and alert the user.
I suppose I haven't exactly answered your question because I'm not that great at JavaScript but I hope this points you in the right direction.
In response to your comment...
I'm unclear on something. If you have to click to start the song then you've already clicked on the SWF and you should be getting keyboard events, right? So if you're having to click to start then click again, maybe you need to make sure your mouse listener is at the root of your display list.
// in your document class / main AS file...
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
Or perhaps you need to poll for input during an EnterFrame loop rather than listen for key events.
I know what you mean. You have a specific object on the stage that needs focus before keyboard events will trigger. I'm having the same issues with a game here. A sprite needs to move with the keyboard arrows but the container needs focus so it will respond. I'm just setting the object I want to move to be tabEnabled as my requirements are only for accessibility purposes so tabbing to the object first will give it keyboard control.

going left: unrestricted / wrapping mouse tracking? in Flash?

So, I'm shooting up dudes in [3D Game], and I can keep dragging my mouse to turn left round and round.
Is this possible in Flash? Or have I misunderstood how the mouse is handled within [operating system] and then passed to the Flash Player?
As far as I am aware, you cannot lock the mouse to the flash window for security reasons - if you could, imagine the flash ad nightmare!
However, Flash does track the mouse position if it does move outside of the window frame. You just have to watch out for clicking - you might have to remap fire to the CTRL key or something.