I've been tasked from my workplace to create a program which, when ran, moves the cursor to over a Windows Toolbar within the Taskbar, and left-clicks it.
The rationale for this is that everyone’s using the same mapped Toolbars on their desktop and considering how tiny the button is to activate the dropdown, and how often we’re clicking on it, it becomes tedious.
I’ve made code to move the mouse cursor to a hardcoded location on the taskbar and send the left-click message, and it works pretty fantastically actually.
The reason why the above approach won’t work however is because everyone’s Toolbars are constantly changing locations (variable number mapped apps on taskbar, docking/undocking laptop from large monitors).
The only thing that’s constant is the name of the mapped Toolbars. What I really need is to determine the screen coordinates for Toolbar “x”, and then move the mouse cursor to that.
I have honestly researched this for some weeks now, looking into UI Automation (people C# one of this is deprecated but not C++), and several other related posts, but with no success. I’ve found a C++ solution, but it didn’t actually include a code example (says “do this, then do that”); plus I’m not as- proficient in C++.
Through Spy++ I’m able to see the coordinates, window handle, etc. for these Toolbars, which leads me to believe this must be possible. FindWindow won’t work because the window handle isn’t constant.
Any help you can provide on this is greatly appreciated.
Related
I want to detect mouse hovering over visual elements in .NET MAUI ( like buttons ). I cannot find any "onmouseover"/"ismouseover" events for this. How can I implement this.
All requests for "desktop" style control of keyboard and mouse have been consolidated under Maui issue: Desktop platforms: Mouse and Keyboard.
jfversluis' comment (at that issue or a related issue) indicates that no work in this area has yet been planned.
That issue is the place to discuss the topic (express interest in, or add any specific requirements or use cases), until there is a plan.
Until then, the work-around is generally to write Windows-only code in the Windows folder of your Maui project.
Unfortunately for mouse, that only gives window or desktop-relative mouse information. AFAIK, There currently is no easy way to interact with individual UI elements while the mouse moves. (Because Maui started as Xamarin started as mobile cross-platform code; touch devices don't have concept of cursor being moved around screen.)
A crude hack is to use AbsoluteLayout: position UI elements at exact positions, so you know where they are, then write (Windows-only) code that does your own "detection".
The next level of sophistication would be to write code that traverses a window's "visual tree" of UI elements, to detect what control the mouse is over. Maui must have such logic internally somewhere, to handle touch events. Unless it relies on each platform's UI code to decide that. TBD.
For now, Maui makes sense for apps that can live with a "touch" paradigm, rather than a "desktop" paradigm.
This isn't an answer per say, but as a suggestion you could try and determine when the mouse would be over the VisualElement and then use StateTriggers to actively apply a VisualState.
MAUI Triggers
I am just a hobby programmer.. and even tough I know how, I don't want to mix windows forms and XNA for my level editor.
Has anyone done this before? Are there any examples around how to create "Windows like" controls for XNA, including events like mouse over, click and double-click and even accept keyboard input(if possible using language specific keyboard input)?
Below you find the basic layout of my editor but it needs so much more.
Yeah.
I'm now creating something like that.
See my project on Bitbucket.
I'm making own lib and voxel engine for Minecraft-like game. Just for fun.
So, in GameHelper lib you can fing folders Input (keyboard and mouse input) and GUI (forms and controls with events). I will be happy if it helps you, but there is almost no comment :P
Examples of use you can find in the Player class in main project (see ProcessInput method).
If you need I can give you better examples :)
Overreaching amateur developer that is outsourcing some of my work and doing part of it as well. I've been working on a dictionary/ thesaurus / spell check & suggestion application that I am trying to get to work on all applications within the windows environment.
I've used hooking to get key stokes and show output as the person is typing for definitions and spelling suggestions. This isn't accomplishing everything I want. Works fine for spell checking and suggestions but to click on a word that already exists or for touch screen interfaces to touch a word it doesn't work.
I was reading the Raw Input API on MSDN and thought that would work but my developer that I've hired is advising me that the RAW input's scope is only on the window that has focus and so cannot do low level hooking. I'm considering giving the effort but wanted a 2nd third fourth perspective prior to making the effort.
MSDN Reference: http://msdn.microsoft.com/en-us/library/ff468896%28v=VS.85%29.aspx
Hope all the background info doesn't take away from the question. Appreciate your insight.
Regards,
John
Yes, he is right. RawInput messages (WM_INPUT) are only generated for the focused window. Maybe you can somehow work around that, but this is not the main problem.
RawInput really gives you, as it's name says, the raw mouse data. This data is only relative mouse-movement or mouse-delta data. The values are still fed into the message when the mouse reaches the edge of the screen, and most importantly for your case: it doesn't give you pointer ballistics (for some explanations on pointer ballistics see this article: http://msdn.microsoft.com/en-us/windows/hardware/gg463319 ). This makes it pretty impossible to determine the actual cursor position.
You could now try to simulate all this behavior, and simulate the cursor position, but pointer ballistics are not the same on different versions of windows. XP has different behavior than Vista, and I think they changed the formular again in Windows 7.
The API suggests, that there are devices, that give you positional instead of relative data, but I've never come across a device that exhibits this behavior, not even touch screens (although this is probably driver dependent), and it certainly doesn't work for a standard mouse.
I would like to establish what is the order of the taskbar items in Windows 7. The reason is that I would like to create an script (written in AutoHotkey or C#) that restore a set of icons to a previous determined order. I wan't to do this because any Virtual Desktop solutions for Windows forget the great and important point of keeping the taskbar item's order, i.e between desktop changes the order of the taskbar items are completely ignored and lost. The reason of why they ignore that fact is maybe because all of them rely in the HIDE/UNHIDE approach, they save what windows are active in any desktop and then between switches they Hide or UnHide the corresponding windows.
I already found a semi solution writted in QT/C++ (Location of app on the Windows 7 Taskbar) that base his function in find the left-upper pixel position of an item based in his color. I don't like that approach because the use of different themes or visual styles would break his functioning. I hope someone has another suggestion. This question differs from that in the link that I'm only interested in the order not in the exact pixel position of any button.
You may want to start with the Windows® API Code Pack for Microsoft® .NET Framework. This API allows you access to several Windows APIs (including certain taskbar functions) from managed code.
However, I'm not certain yet that it allows for functionality regarding the task bar in general vs. a specific application's taskbar entry. I will continue researching this and update if/when I find more information.
I've written a WPF application (in Visual C# 2010 Express) that has 2 windows. The 1st has a various buttons, the other displays video using the MediaElement control. When a button is pressed, a video associated with it is played or stopped if it's already playing.
On my development machine (Windows 7, good graphics card, lots of memory etc), this runs fine. The only problem I've encountered is that when attached to the debugger it is very unstable but when run normally these issues go away.
Unfortunately when run on a much less powerful XP machine the videos run at 1-2fps. This is despite the fact that the videos run fine in Windows Media Player.
There seem to quite a lot of reports of poor performance for the MediaElement control (not to mention inconsistencies in what it can play) so I decided to look at some alternatives.
I tried a free library call WPF MediaKit (http://wpfmediakit.codeplex.com) that I thought might have some effect, however while I've got it to work on an XP machine, it resolutely refuses to display videos on my development machine despite using exactly the same code. I'm still hoping I can this to work but I'm not confident it will help given it's still using the MediaElement control behind the scenes.
I then tried using wmp.dll COM control (Windows forms rather than WPF) and even with the simplest app (new Windows Form project, WMP control added to form, and 1 line of code to set the URL on load) I get odd behaviour. With the debugger attached, it works across multiple monitors, but sometimes when it starts playing, it just repeatedly stutters over the 1st few frames and the only way to break it out of this seems to be to move it to the other monitor. If I'm not using the debugger, I don't seem to get the stutter issue but the video is only displayed on the main monitor, as soon as I move the window to the secondary monitor, it goes black.
So my question is has anyone experienced anything like the above and/or have a decent solution to it? It would be especially nice to find something that works consistently with and without the debugger attached!
Have you tried this library?
http://directshownet.sourceforge.net/about.html
There's also this .NET interface to VideoLAN media player, but that introduces a dependency to VLC:
http://wiki.videolan.org/.Net_Interface_to_VLC
WPF MediaKit does not use MediaElement behind the scenes, but instead uses the D3DImage interop class to provide high performance video to WPF.
WPF in XP has always been a hit-or-miss in terms of performance. You might want to take a look at the rendering tier to ensure WPF is fully hardware accelerating. Also make sure you have the newest video drivers available and that the GPU is capable.
-Jer