I'd like to instruct users of my app to either "click" or "tap", depending whether they have a mouse or a touch screen.
Basically I'd like to do something like this:
if(Controls.hasMouse())
ShowMessage("Click here to continue");
else
ShowMessage("Tap here to continue");
Any ideas how to detect if a mouse is connected to the system?
I found a solution to the problem:
using namespace Windows::Devices::Input;
MouseCapabilities^ mcap = ref new MouseCapabilities();
bool has_mouse = mcap->MousePresent == 1;
Related
[Question]
On Windows Phone 8.1, what exactly happens in between the time when the user leaves the app and the OnSuspended event fires? I'm having trouble with the ability to manage objects in that span, in particular MediaCpture object.
To better explain the problem, here is the scenario:
The user is on a page with a video preview being pumped to a CaptureElement
The user taps the Start button
The user taps Back button and returns to the page with a broken MediaCapture
With WinRT there isn't an ObscuredEvent and OnNavigatingFrom doesn’t fire unless you’re going to another page in the same Frame. After some investigation, I've found that the only event that fires is Window.Current.VisibilityChanged
I've gone ahead and hook it when the page is NavigatedTo and unhooked in OnNavigatedFrom (see ex2 below). Inside the event, I check for parameter that tells if the app is hiding or showing and dispose/initialize accordingly(see ex.1 below).
[Problem]
However, this only works with the debugger attached. If I do this without the debugger attached, it doesn't reinitialize and frequently crashes the camera and I have to literally reboot the device.
Code Example 1 (note: e.Visible == false is leaving the app and true when returning)
async void Current_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
{
if (!e.Visible) //means leaving the app
{
await DisposeAll(); //cleans the MediaCapture and CaptureElement
}
else
{
if(mediaCaptureManager != null) await DisposeAll();
await Initialization(); //set up camera again
}
}
Example 2 (hooking into the event)
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Window.Current.VisibilityChanged += Current_VisibilityChanged;
this.navigationHelper.OnNavigatedTo(e);
}
protected async override void OnNavigatedFrom(NavigationEventArgs e)
{
Window.Current.VisibilityChanged -= Current_VisibilityChanged;
this.navigationHelper.OnNavigatedFrom(e);
}
[Update: Resolution]
Instead of using VisibilityChanged, hook into Window.Current.Activated on the page's constructor. With the debugger completely detached, the Activated event will provide the WindowActivationState parameter in the WindowActivatedEventArgs. Like this:
private async void CurrentOnActivated(object sender, WindowActivatedEventArgs e)
{
if(e.WindowActivationState == CoreWindowActivationState.Deactivated)
{
//dispose MediaCapture here
}
else if(e.WindowActivationState == CoreWindowActivationState.CodeActivated || e.WindowActivationState == CoreWindowActivationState.PointerActivated)
{
//initialize MediaCapture here
}
}
See my answer in https://stackoverflow.com/a/28592882/3998132. Using Window.VisibilityChanged in conjunction with your Page\UserControl Loaded\Unloaded handler should solve your issue I believe.
Using Window.Activated is less desirable than Window.VisibilityChanged because Activated relates to being visible AND having focus where as VisibilityChanged only pertains to visibility. For showing a preview having focus is not applicable. Since Windows Store apps on Windows Phone can only have one Window showing there is no difference in using either however if your app becomes universal and runs on let's say on Windows 8+ Modern shell (which can show multiple Store apps with the Snap window feature) or Windows 10 desktop (which can support multiple Store apps showing at the same time) you will not want to stop preview when a user changes focus from your app but your app is still showing.
I'm not sure if it wouldn't be more suitable to use Suspending/Resuming events. Note only that in this case, you will have to debug it properly - it behaves little different while being run with/without debugger attached.
As for the code - hooking your event in OnNavigatedTo/OnNavigatedFrom is not a good idea - when the OS suspends the app and you are using SuspensionManager then OnNavigatedFrom will be called, but when you go back to your app (resume it), then OnNavigatedTo will not be called.
Using Window events may also work here, but why not subscribe it once, somewhere in constructor? - it's window-wide and hence in phone there is only one window, which stands for app, then subscribe once. In this case, you may add a line that recognizes the current page in window and if that page contains mediacapture then dispose (create similar). Then you can also dispose/initialize in navigation events in case user doesn't leave your app and just navigate.
please can somebody tell me how remote control works? I have to create presentation in Flash platform using ActionScript 3. How to listen keys from remote control to show next slide, prev slide, pause, play etc? Is it like normal keys?
thanks for info
Generally projector remote controls are just left and right mouse click signals. LMB is the 'next slide', RMB is the 'previous slide'.
You're going to run into problems though, since right clicks in Flash open the context menu. Flash isn't really well suited for this purpose as you can see.
I recommend adding your Flash files into a PowerPoint presentation to save yourself all the stress of second-guessing which hardware is available to you.
When programming your flash presentation for use with a remote clicker, do not target left and right mouse clicks.
Instead you need to use keyboard events to target Page Up and Page Down.
The event listener that emulates the remote clicker's forward arrow is:
stage.addEventListener(KeyboardEvent.KEY_DOWN, forwardsFunction);
function forwardsFunction(event:KeyboardEvent):void {
var myKey = event.keyCode;
if (myKey == Keyboard.PAGE_DOWN)
{
The event listener that emulates the remote clicker's backward arrow is:
stage.addEventListener(KeyboardEvent.KEY_DOWN, backwardsFunction);
function backwardsFunction(event:KeyboardEvent):void {
var myKey = event.keyCode;
if (myKey == Keyboard.PAGE_UP)
{
This will allow you to use a remote clicker to work with your Flash presentations. At least this is the case with the Logitech remote I have tested.
Also, I found it necessary to determine the focus for this to work. My Actions were placed on a frame at stage level, ie they related to movieclips placed on the stage. Adding this code to the start of my Actions enabled this to work:
stage.focus=stage;
I go this response in Certification report:
The app does not appear to fully support touch input. The various
tiles on the main screen respond to touch/clicks but do not launch an
action. Touch support in this app do not appear to work to our
reviewers. Please see:
http://msdn.microsoft.com/en-us/library/windows/apps/Hh761498.aspx for
some of the common interactions for keyboard, mouse and touch.
This has never been an issue while developing and testing on several desktop computers and Surface RT. Any ideas on what might be the cause, or how I might reproduce it? The actions mentioned are hooked up to event handlers in code behind and use the navigation model with view models as parameters. I can post an example if needed, but there is nothing special in that code. What could cause a event-bound button to appear to be pressed but not call the handler, on some environments?
Extracts from one of the main features that the testers mention as non-functional:
View:
<GridView ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
ItemClick="ItemView_ItemClick"..
Code behind:
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
var foodItem = (FoodItemViewModel)e.ClickedItem;
var mainViewModel = (MainViewModel)this.DefaultViewModel["MainViewModel"];
mainViewModel.CurrentItem = foodItem;
this.Frame.Navigate(typeof(ItemDetailPageReadOnly), (MainViewModel)mainViewModel);
}
From ItemDetailPageReadOnly:
protected override void LoadState(Object navigationParameter,
Dictionary pageState)
{
if (pageState != null && pageState.ContainsKey("SelectedItem"))
{
navigationParameter = pageState["SelectedItem"];
}
var mainVm = (MainViewModel)navigationParameter;
this.DefaultViewModel["MainViewModel"] = mainVm;
this.DefaultViewModel["Item"] = mainVm.CurrentItem;
}
I would expect a NullPointerException if any of the parameters were null, not the described behavior from the testers.
you should use one of the higher level events unless you need to respond to a specific portion of the gesture. http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994936.aspx
i saw some online flash games can do this:
when you switch your current web to other windows or other web tabs, the application program will draw a black block and tell you've leave the application, click on the flash area to resume .
i've tried some event like focus in and out or mouse leave on the stage,but the reaction isn't what i expected.maybe i use them in the wrong way .please tell me if you got the solution.
var count:int = 0;
this.stage.addEventListener(Event.MOUSE_LEAVE,function(e:Event):void
{
//only be called if your mouse cursor leave the area,but can't detect whether you're actually switch to other program.
trace('mouseleave',count++);
});
this.stage.addEventListener(FocusEvent.FOCUS_OUT,function(e:Event):void
{
//no reaction
trace('focus out',count++);
});
this.stage.addEventListener(MouseEvent.ROLL_OVER,function(e:Event):void
{
//no reaction
trace('mouseenter',count++);
});
There are two methods:
Use Event.ACTIVATE event. But a swf should be on focus before.
Use JavaScript call from ActionScript to check is a window or a tab on focus.
I want to create an AIR application in which i need to show the notification that when AIR application is minimize then at some interval of time message shows from the system tray similar like giving information.
I have visited this LINK, its a nice component but tutorial is not that much good as component. I need to create a component like that or source is available from this site so modification in this component will also be acceptable. so please help me.
EG: When you minimize the Yahoo Messenger and some one is sign-out or sign-in then it gives notification i want component similar like that...
Thanks in Advance
First Step, We have created a Custom Popup control for Notifications display.
In the second step, we have controlled the display of that popup using the following code
if(!this.stage.nativeWindow.visible || this.stage.nativeWindow.displayState == NativeWindowDisplayState.MINIMIZED)
{
stage.nativeWindow.alwaysInFront = true;
fadeTimer = new Timer(5000,1);
fadeTimer.start();
fadeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, fadePopUp);
popUpWindow = new PopUpWindow();
popUpWindow.isAlerts = true;
popUpWindow.Message = "<b>You have "+event.numNewMessages+" new notification messages<b>";
popUpWindow.type = NativeWindowType.LIGHTWEIGHT;
popUpWindow.open(true);
popUpWindow.fadeInEffect.play();
popUpWindow.nativeWindow.x = Capabilities.screenResolutionX - popUpWindow.width - 10;
popUpWindow.nativeWindow.y = Capabilities.screenResolutionY - popUpWindow.height - 35;
}
The condition used above is what we have used to find out, whether our application window is minimized to System Tray or not. Even though it is not a perfect fix, It didn't fail me yet. It's quiet stable for my app.