direct x mouse recapturing problem - directx

i have a direct x c++ game. i use my own mouse icon and capture the mouse and keyboard when the game initialises but the problem is that if i minimise the game and select another window, for example to skip a song media player when i go back to my game screen the mouse no longer works.
as far as i understand it i need to re capture the mouse handler every time the application gets focus but how do i do this.
can i simply re use the same mouse code from the initialisation and if so where do i put it to make it run when the application regains focus.
fyi my game runs in both windowed mode and full screen would this make a difference.
thank you

First of all, I would advise to use the Windows cursor API instead of drawing the mouse yourself. It will be much more responsive (not suffering from low fps etc.) and it is much easier to handle. You can use animated cursors this way too.
For capturing the mouse, you can only really capture it while a mouse button is pressed. If no button is pressed and the mouse is moved outside the application window, you lose the capture.
Why do you even need to capture the mouse? You get WM_MOUSEMOVE messages etc. when the mouse is not captured.

Related

Register multi-touch as a single touch?

Is there a way to register multi-touch as a single touch? Say if I use three fingers to tap a large button, can it be registered as simply one tap of the button? -- the current default appears to treat it as a multi-touch, and as a result ignores the button-pressing altogether. Similarly, if I use my palm to tap a large button, the button isn't pressed either.
I noticed in iphone Accessibility Settings -> Touch Accommodations, one could set "Ignore Repeat" and "Use Initial Touch Location" for tap assistance. Of course, if those are turned on, it affects the entire phone instead of just one app. But would that be the direction to approach this problem?
BTW I don't actually need multi-touch in my app. So if turning off multi-touch can be more simply done on the whole-app level instead of button-by-button, it would suit this case very well.
Thank you #DonMag for providing a hint.
So, if yours is an ios app from Capacitor, here is how to change your javascript code:
Change your button onClick events into "onTouchStart"
Use a state variable to keep track of whether "onTouchStart" is triggered and the resulting logic is executing. During that execution, prevent more touch events to have further effect on the button. This is to prevent the button from being pressed in quick succession by multiple touches that come from, say, your three-finger tap or palm tap. Only after the execution is finished do you revert the state variable back to the original value, so that the button is ready to be pressed again.
If there is an answer that's more suitable for the native Swift bundle I'll accept that as the answer. The above is just to help anyone who may encounter the same problem as mine.

Detect palm touching/releasing the iphone screen

Implementing a sort of 'distress call' button which should work as following:
User starts application and covers a screen with a palm of a hand
Some time passes, user may introduce additional touches during that time or remove some of the existing (but not all of them), location/shape of touches may change
When user releases a hand (i.e. removes last touch) a distress signal is emitted by the app
Basically, the app should register two events: (1) a screen is touched (2) all touched are released
I'm trying to use touchesBegan/touchesEnded methods and those work for small area touches (fingertips) but on touching screen with a full palm or even only palm edge a touchesCancelled gets triggered immediately while hand is still on the screen. Obviously no other events are emitted upon hand release afterwards.
I tried subclassing UIWindow and UIApplication and overriding sendEvent in those but got no additional info - large area touches are triggering touch begin and immediately touch cancel, releasing hand afterwards emits nothing. In some cases large area touches fire no events at all, not even the touchesBegan. Basically, iOS doesn't let me work with a very basic scenario - detecting just the fact of screen touch/release.
Is there any way to query the screen touch state directly and not work with responder chain? Or suppress the cancellation event from firing? Or maybe I'm missing something?
Unfortunately, as of right now, no solution exists

iOS Magic Keyboard APIs

Is it possible to intercept the trackpad events from the magic keyboard (with trackpad) in an iOS app and process them myself while hiding the pointer and not sending these events to the UI, or is that not possible?
Think about a game for instance where the user would move their finger around on the trackpad to move a character around on screen, but you wouldn't want to show the pointer circle and the location on the screen doesn't matter or if/where they click, you are just using the change in position as they move their finger on the trackpad.
Thanks

Delphi - Simulate Click Animation

This is my first post here on stackoverflow so forgive me for anything I'm doing wrong.
I'm making a kind of guide to the users without any computer knowledge of my application where I show him how to use it by signalizing what he should do, more specifically where to click. I want to that by moving a "fake" cursor to the button and simulate a click, and here is where I got my problem, I have to simulate just the animation of the click, and not the event itself but I couldn't find a way to do that, can anyone help me?
What you're describing is exactly what WH_JOURNALPLAYBACK is for. It populates the message queue with the mouse and keyboard messages you want to occur, and the OS interprets them. In your case, activate the playback hook and perform the mouse events necessary for performing a click.
In preparation, you'll probably want to use WH_JOURNALRECORD to discover what messages you need. Once you have them, you can probably winnow them down to a reasonably sized list prior to shipping your product to customers. (In particualr, you'll probably record many more mouse-move messages than you really need.)
In your button's click handler, check whether playback is active. Only perform the rest of the event handler when playback isn't active. That way, your program will behave just as though the button were clicked (including any animation), but it won't execute the real event code.

AS3 Run code continuously while holding a Button down - Air For iOS/Android

I am developing an iOS game in Flash CS6.
I have a basic movement test that I put in an Event.MOUSE_DOWN handler.
What I'm expecting/wanting is when I held my finger down on the button, that the player would keep moving until I stop touching the screen.
What happens though, is I have to keep constantly tapping to keep the player moving - rather than just hold my finger on the button and the player keeps moving.
What code should I use to accomplish what I want?
To accomplish this, you'll need to run a function continuously in between MouseEvent.MOUSE_DOWN and Event.MOUSE_UP as MouseEvent.MOUSE_DOWN will only get dispatched one time per press.
Here is a simple script to do just that:
myButton.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
function mouseDown(e:Event):void {
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp); //listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.
addEventListener(Event.ENTER_FRAME,tick); //while the mouse is down, run the tick function once every frame as per the project frame rate
}
function mouseUp(e:Event):void {
removeEventListener(Event.ENTER_FRAME,tick); //stop running the tick function every frame now that the mouse is up
stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUp); //remove the listener for mouse up
}
function tick(e:Event):void {
//do your movement
}
As an aside, you may want to use the TOUCH events, as it gives more flexibility with multi-touch control. Though if you're only ever going to allow one item to be pressed at any given time, it's not an issue.
TO do that, just add Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT in your document class, then replace your MouseEvent listeners with the appropriate touch event:
MouseEvent.MOUSE_DOWN becomes: TouchEvent.TOUCH_BEGIN
MouseEvent.MOUSE_UP becomes: TouchEvent.TOUCH_END

Resources