question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gather keyboard input

See original GitHub issue

In UWP, this would be how I get keyboard input for a Xaml application …

Microsoft.UI.Xaml.Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;

This doesn’t work for WinUI, with output… Microsoft.UI.Xaml.Window.Current.get returned null. How do we get keyboard input for the Window?

I should mention that gathering from a control, such as SwapChainPanel also doesn’t work. It’s a pretty weird design for sure.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Gavin-Williamscommented, Jan 21, 2021

My app isn’t UWP, but I’m using as much UWP code as possible, because really, all I want is UWP (with .Net 5 + NoOverlays + Steam support) which is only available via the desktop app model. If .Net 5 gets UWP and UWP get’s Overlay suspension and .Net 5 compilation to get away from .Net native then I will likely go back to UWP. But we are stuck on what’s being called Desktop - even though UWP is desktop as well.

From my perspective, Microsoft have introduced a new window model - the HWND - it’s something that was used historically, many years ago, before my time, and they’ve brought it back, because nostalgia. It’s weird because I’ve been using CoreWindow and I thought with .Net 5 we were getting a new unified App/Window model and framework. Instead, I have to dig into god knows where to get keyboard input, and I need to write redundant code to support this legacy thing.

“CoreWindow has sandbox restrictions” - What sandbox restrictions are you referring to that are related to how we get input? How does providing CoreWindow functionality to desktop apps break … well anything?

And none of this helps with creating a sensible, consistent and modern way to get keyboard input from the Window or SwapChainPanel. I mean, I’m sorry, but wrapping an SCP in a Grid, when it’s already a Grid just to get keyboard input because the Window doesn’t give me keyboard input is just plain goofy. Unless there is something I’m missing?

2reactions
mdtaukcommented, Jan 21, 2021

My app isn’t UWP, but I’m using as much UWP code as possible…

Well for the foreseeable, CoreWindow is off limits. That is why it returns NULL

You will have to do it the Win32 way until more fundamental changes come, probably through Reunion APIs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keyboard Shortcuts
You can view the full list of shortcuts below or by going to Menu > Settings > User > Keyboard Shortcuts while in...
Read more >
How to Gather User Input via Keypad (DTMF Tones)
In this guide, we'll show you how to gather user input during a phone call through the phone's keypad (using DTMF tones) in...
Read more >
Gather Town Android Phone Virtual Keyboard - YouTube
Remarks: After install, please enable keyboard, select u input languages, set u input method to Hacker's Keyboard.
Read more >
Get User Input from Keyboard - input() function - Python
The input() function gets user input (keyboard) and stores it into variable name. Here name is a variable. The print() function shows it...
Read more >
5 Unique Hotkeys in Gather Town You Need to Know
You can Press 1 to 6 on your keyboard to give emoticon. Its quite mini feature, but it work well to give a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found