Unity: Passing information between two programs [duplicate] - c#

This question already has answers here:
Send message from one program to another in Unity
(2 answers)
Closed 4 years ago.
I'm trying to design an app launcher system, and have figured out how to make the launcher run an app at path/app.exe, as well as attaching a listener to that process to detect when it has been closed.
Obviously, during this process, the launcher will lose focus as it moved into the background. Is there a way for it to continue to listen for keyboard input and perform an action in the background. It would be ideal if the launcher can then pass information to the running application, all without the application losing focus.
It is worth noting that both the launcher and the app will be made in Unity with c#, so if there is a solution that involved the app setting up some sort of listener for the launcher then that would be good, but for security reasons, the launcher must be the process that listens for the keyboard press action.

There are some approaches to Interprocess Communication in the .NET Framework, of wich you can pick your Poison:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574.aspx
It is also possible to intercept Keyboard events via low Level Keyboard hooks. However those require you use a unamanged Windows API. That in turn means, that you have left Managed Code: https://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hook
The biggest uncertainty here is Unity. Usually Unity targets the Mono Framework. I am not sure wich IPC options Mono has. Also Unity is usually for programms that run on more then one OS (Linux/Windows/Mac compatibility). And that will limit your IPC options even more. And ruin your chances of getting Keyboard hooks going.

Related

Global HotKey in Universal Windows App

So I created an UWP App that can record several Audio Lines and save the recordings to MP3 files for in-game multi-line recording that I can later edit separately (game audio, microphone, game comms, voice comms) as NVidia ShadowPlay/Share does not support this yet. I achieve this multi-line setup with VAC.
I have a version of this tool written in regular Windows WPF C# and I have a system-wide HotKey Ctrl+Alt+R that starts/stops recording so when I'm in a full screen game, I can start/stop recording without exiting full screen mode (switching window focus).
Can a global (system wide, app window not in focus) HotKey that triggers some in-App event be achieved in a UWP App? I know the functionality is not supported for other platforms. But I only need it to run on Windows 10 Desktop and the HotKey support is mandatory. Or can I achieve my goal in any other way for UWP Apps?
GOAL: System wide key combination to trigger in UWP app event without switching Window focus and messing with full-screen games.
at the moment it is not possible to solve this task thoroughly.
You are facing two limitations of UWP and can be only partially solved:
Lifecycle: UWP apps go in suspended state when they are not focused. They just "block" to consume less resources (and battery). This is a great feature for mobile devices, but is bad news for you project. You can solve this by requesting "ExtendedExecutionSession" which will guarantee that your app never falls asleep when out of focus if "attached to wallpower".
Detect input without focus. It's clearly stated on MSDN that UWP doesn't support keyboard HOOKS (this refers to SetWindowsHookEx). They reinvented "GetAsyncKeyState", now it works only when the Windows is focused. Indeed you can find that under CoreWindow.GetAsyncKeyState().
If you only need to use F Keys as hotkeys you can still do something, like "press F2 when the app is minimzed to activate a function".
Use Stefan Wick example. He solved part of the problem.
Instead if you need to listen to lots of keys (or mouse events) there isn't a way. You can't right now.
Curiosity
UWP has restricted capabilities, one of which called "InputObservation".
At the moment it is not documented and impossible to implement (unless you are a select Microsoft Partner), but it should allow apps to access system input (keyboard/mouse..) without any limitation and regardless its final destination.
I think this feature is the key for system-wide inputs detection.
I am not able to find a way to implement it.
Kind Regards

Event to detect when a system wakes up from sleep in ASP?

I know this question exists:
Event to detect System wake up from sleep in C#
However, that appears to be only for WinForms. I need to do this from an ASP Intranet application written in C#. Is this possible?
It's not possible to detect system events on the client side (browser-side) of a web application (not without some plugin that can directly interface with the browser and with the OS).
Using a native plugin this would be doable but then the plugin would have to be implemented for each browser / platform that you intend to support.
If your application is strictly an intranet application and you have control over what browser is used and on what platform(s), adding a plugin to the browser may be a lot less work than in the general case.
Based on my experience, it's best to implement such plugins using C / C++, not C#, so you avoid various issues with trying to load the .NET framework into the browser process. This may have changed, though - I only did IE plugins and it was some years ago.

Programmatically communicate with multiple unfocused VMWare instances with C#

Even though my long title spoils quite a lot of my question, I'll try to be more specific here.
I have 5 VMWare instances that all have their own tasks to do. They are hosted on one same computer. But I need one program (that I'm actually writing, duh) to get informations and to send informations such as keystrokes and mouse clicks. But from what I've red so far, communication between programs is quite hard to achieve and I haven't found any way to send keystrokes to an unfocused or reduced VMWare windows. Plus I would need to send different and specific keystrokes to each of my 5 VMWare instances.
My program will starts itself each 5 tasks in each 5 windows. The order doesn't matter as long as each instances have its own tasklist. I would need a way to keep track on each window's identity so I don't send let's say window 4's keystrokes to window 5. I would also need to be able to check periodically if each VMWare's instances is doing its job. Additionnaly my VMWare's instances are all running in a win7 environnement.
Now that the whole situation is explained, I'll sum up the question I'm currently submitting. Is there any way for my C# program to keep track of 5 VMWare's instances' identities and both send keystrokes (+ mouseclicks) and get at least screenshots of what's displayed on each of them even though they are reduced or unfocused ?
Thanks a lot.
Is there a way to get
You have an incorrect understanding of how VMWare works. VMWare isn't "running in a window". VMWare is running in a virtual machine at a very low level in your computer. What you see as a "window" is merely a "viewer" that allows you to connect to the remote machine (even though it's running on the local computer). This "viewer" is an application similar to the remote desktop client, or a VNC client. As such, there is very limited interaction between the OS and the host OS and the applications running in the guests.
This means that your host OS doesn't know anything about the individual applications running inside the guest OS, and you can't see it's window handles, or control mouse or keyboard events. In fact, the VMWare drivers "capture" the hardware and steal these events directly from the hardware, so there is no real way for your application to simulate a human interacting with the Virtual machine window.
What you COULD do, and this would be a lot of work, is create "agents" on each of the virtual machines that would have access to the applications running on them. These agents could listen for events on the network, and you could send events to them to do what you want. However, as I said.. this is likely a lot of work.
This whole thing sounds kind of cheesy to begin with, like you're trying to do something the hard way, but since you haven't told us what you're ACTUALLY trying to do.. we can't suggest any better alternatives.
A quick and dirty approach is to look into Visual Studio Test Controller and Agents. The idea is to install the agent on each one of the machines. You can then leverage the MSTest framework (wrongly called unit tests) to execute you c# code one each agent.

how to write a background application,that can be run without any UI [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
how to automatically launch the application in wp7 without user actually clicking on the icon
how to write a background application (one that can be run without any UI)
any examples??
Thanks
It is not possible to create such applications for Windows Phone 7.
This was a deliberate design decision when the platform was created as such applications have a negative effect on battery life and device performance. They also break the desire of the platform to have transparency to the user about what the phone is doing. (i.e. it doesn't do anything the the user doesn't explicitly action themselves.)
An installed application (which has a UI component) can also use background agents (see http://msdn.microsoft.com/en-us/library/hh202942(v=vs.92).aspx) to perform some actions when the UI portion of the code is not running but there are a number of limitations on what they can do and how often they can run.
Actually, it is possible, but requires so many hacks, that probably the OA will not get into this.
For anybody interested, please search the xda-developers forum, under wp7 hacking, and at the current point of time and knowledge - search under native development and preparing custom ROM images
and do not try to spam there, or the FSM will eat your brain
BTW. have you tried redefining/solving you prroblem with http://channel9.msdn.com/posts/Mango-Jump-Start-06-Windows-Phone-Multi-tasking--Background-Tasks ? // edit, ah, Matt has a better link for that

How to receive the windows messages of an unmanaged Win32 and Win64 app in C#?

I have an unmanaged app both in 32 bit and 64 bit on Windows 7 64.
I want to write a C# application to receive the keyboard messages it's receiving, so I could do certain things on certain key presses, and for others, simply send it back to the app, so as not to interfere with them.
I don't know the right way to search for this so not sure how this would be done.
Also I want to avoid using keyboard hooks if possible. Just want to receive the app's keyboard messages is what I am trying to do.
That's what keyboard hooks are designed for. There aren't any alternatives that don't have all the problems of keyboard hooks (and probably some additional ones).
See here about adding hooks to specific windows. I've no idea how to read the message pump of other apps. You can do it with a IMessageFilter but it only will work in the current app...

Categories

Resources