(Monogame) Keyboard input not being recognized - keyboard-events

Just got into monogame today. Noticed that my software wasn't taking any keyboard inputs when I tried to bind a key to a fullscreen toggle. Weirdly enough, it takes inputs from my controller just fine, but just not the keyboard. Keyboard.GetState().GetPressedKeyCount() also always returns 0, so I've got no idea what's causing the problem.
I'm not usually one to attach full code files, but the program loop class is only 72 lines, so it's here if it helps: https://pastebin.com/xcWnDvqL
Platform: Windows 10 Build 19044
Monogame Version: 3.8.0.1641 (DesktopGL)

I tried to set up my project the same way as you did, but I am unable to reproduce the issue. It probably has something to do with your system. You can try the following and see if it works for you.
Now this may sound silly, but when you provide input, are you sure the window is active?
Your game can detect input from the gamepad even when the window is inactive, but the same is not true for keyboard input. I noticed this while testing your program. So ensure that the window is active (by clicking on your game window) before pressing a key and see if the game is still unable to detect input.
I hope that this is the problem in your case. If not try the other fixes as shown below.
Update the Monogame packages.
The latest version of monogame available is v3.8.1, so you can update your templates.
Proceed to install the latest nuget templates (as it was mentioned by Monogame that many bugs have been hotfixes in this version. You can do so by doing the following in a terminal.
dotnet new install MonoGame.Templates.CSharp::3.8.1.303
Then proceed to make a fresh desktopgl or mgwindowsdx project and see if the issue persists.
Check for driver issues.
Monogame uses xinput/DirectInput(a package in DirectX) to detect input from the input devices. Maybe the issue has something to do with it. You can search and run dxdiag from the start in windows. Ensure your drivers (including video drivers) are up to date.

Related

WPF application freezes when rendering text (wpfgfx issues)

TL;DR:
application is built with WPF, running on .Net 3.5
newest and older versions of the app work properly on many different machines
on one specific machine it malfunctions in a strange way:
either does not start, displays black screen instead of "welcome" screen; can't do anything on that black screen
or does start and works properly, until a TextBox is presented and until the user starts entering the text into it; then application immediatelly hangs
Background:
I have built a WPF application on .Net 3.5. I've checked the application on various machines with different OS, ranging from Windows XP up to Windows 7 - and it runs fine, no bugs, etc. It also works fine on my client's several target machines, XP and W7 included again.
However, on one machine, it suddenly ceased to work. My client sent me the machine so I can investigate. From the files on its drives, I can see there were older versions, and they were used by the client for a few months. I also see that the newest version is not installed yet on this machine. So, I tried running the old versions first, to see what's the problem.
What user sees:
oldest versions (say, v1, v2) of the application does not work at all. When they start up, the only thing the application displays is ... absolutely completely black window. There should be a "welcome" screen, composed of few images and labels and a button. The app is not frozen it is "responsive" (Win7 can communicate with it, the window is not dimmed).
last (but not newest, let's name it v3) application runs fine, everything is clickable, features work OK, except one. When user is asked to provide a password, the user is presented with single TextBox in a popup. When the user enters at least one character in that textbox, the application freezes. It freezes even before having rendered the masked '*' of the password. The freezing is total, the application stops responding (the window is dimmed and the OS wants to close it), CPU goes to 100% (actually 50%, two-core system) and the only way to stop is kill it via task manager.
then I installed and tried running the newest version (v4) - it behaves just like v3 above
I've also tried reinstalling all the versions, just to be ensure the .EXE/.DLL files are not damaged - no changes (v1/2 - black, v3/4 - freeze on text)
Technical bits, just FYI:
The app is very simple, one executable with no shared libraries and no shared configuration. There is just no way the newest version could interact with old versions. Seriously, I intentionally made the app in a way it can be "just copied" and several instances can be safely kept in separate folders.
All versions of the app (v4, v3, v2, v1) work properly on all other machines, with various versions of Windows
The problem can't be related to user files or configuration, I tried copying them from problematic machine to healthy ones, and the problem does not repeat
Related to password box: There are absolutely no event handlers in the code that could produce a deadlock or freezing. The password textbox has no text-changed handlers. My code reads the text only after an "OK" button is pressed. The app freezes immediatelly when user enters first character, the
user does not even get a chance to press "OK"
Related to startup: The app does almost nothing on startup. It merely displays some form of a splash/welcome screen. There is no logic there except for a nice UI and one button. The user has no chance of pressing that button. When the app starts, the screen is black and has no contents, not even the splash/welcome image.
Tracing and observations:
I've focused on the TextBox part, since it's more granular.
I've got the app to freeze again, and checked the threads with ProcessHacker.
Except for typical threads, one thread that was sitting and busy-spinning at:
wpfgfx_v0300.dll MilGlyphRun SetGeometryAtRenderTime
wpfgfx_v0300.dll MilGlyphRun SetGeometryAtRenderTime
...
wpfgfx_v0300.dll MilContent DetachFromHWND
That's certainly problem with the WPF layer itself. The DetachFromHWND tells me close to nothing, but MilGlyphRun is surely about the text rendering. It freezes while trying to render the text. I've checked the black-screens on older versions of the applications, but I couldn't catch it, since the apps were not frozen, just black.
So..
I've applied literally all pending updates (like, 150 of them, ~800 Mb, most of them were to the OS and .Net framework)
I've tried reinstalling all video drivers
No changes, still black screen, still freezing.
So, focusing back to the problem. It failed to render a text. Sounds obvious, since it deadlocked when user entered a character into a textbox, but it's damn not obvious! The user was presented with tons of different TextBoxes until he finally got to the PasswordBox. All TextBoxes worked OK, only this one fails. And why old verions of the app display black screen and the new version displays the "welcome" screen properly? How can be those issues related?
The connection is: Windows Presentation Foundation Font Cache service.
Sources:
http://support.microsoft.com/kb/937135
http://social.msdn.microsoft.com/Forums/vstudio/en-US/7cc032c1-5f4d-4518-adc6-f53afd051e6b/presentationhostexe-running-at-50-cpu?forum=wpf
WPF uses a Font-Cache service, running as a separate process, for, well, caching fonts. Whenever your WPF app needs to draw some text, it might ask the cache service for fonts. Once in a while the font cache might get corrupted and it then will/may randomly impact any WPF application.
Unfortunatelly, restarting the service is not enough. When this happens, you must delete all FontCache files that this service keeps on the disk. Before deleting them, you must stop the "Windows Presentation Foundation Font Cache service (or whatever it's called in your languge, for example Usługa buforowania czcionek platformy Windows Presentation Foundation in Polish..). Then, go to
Win7: %systemdrive%\Windows\ServiceProfiles\LocalService\AppData\Local\
Vista: %systemdrive%\Windows\ServiceProfiles\LocalService\AppData\Local\
WinXP: %systemdrive%\Documents and Settings\LocalService\Local Settings\Application Data
and remove all files looking like FontCache.dat. The source articles mentioned only one file (FontCache3.0.0.0.dat, but in my case there were around 8 files with similar naming convention).
After deleing them and restarting the service, all versions of my application were running properly again. No black screens, no freezing on textbox.

Opening Windows console programs in Full Screen Mode

I am developing a C program that prints out a message. The problem with it is that when I run its .exe file, it does not run in fullscreen (until I press alt+enter to force it to full screen). I want the program to run in fullscreen itself when I run it. Is there any way I can do it?
Thanks in advance.
You could call SetConsoleDisplayMode() to force CONSOLE_FULLSCREEN_MODE. Beware that support for this has been disappearing. The last machine I owned that could still do this has been gathering dust for quite a while already. Along with the memory of the loud relay clicking sound, mixed with the high-pitched wail of the flyback transformer in the CRT.

Debugging Silverlight in Visual Studio 2010 freezes when using keyboard

First I'd like to head off the "wait a minute" questions.
Yes, I've read every thread with similar titles and subjects on SO and beyond.
Yes, I'm using the very latest version of SP1 and any potential hotfixes that might be related to this problem.
So, with specificity, here is my problem:
When I'm debugging Silverlight applications and it hits a breakpoint, everything works just fine as long as I use the mouse. I can continue, step, stop debugging, disable and enable breakpoints all just fine -- as long as I do so with the mouse.
But when I use the keyboard, Visual Studio freezes for a number of seconds, sometimes over a minute. This is any use of the keyboard. But after a short time, it starts to work just fine until that debugging session is over. But the next debugging session (regardless of whether I use the same instance of Casini or not) it will do exactly the same thing.
When I say any keyboard use, I mean it. F5 (Continue), Shift-F5 (Stop Debugging), F10 (Step Over), as well as typing in the Immediate window or even hitting the ALT key to highlight the menu.
For instance, if I try to type something in the Immediate window, it freezes for about 15 seconds and then shows the first key and repeats the pattern about 5 times until it releases and everything is just fine.
When I say "freezes" I'm not talking just Visual Studio but it hangs the entire operating system except for my ability to move the mouse. Even so, the mouse cursor remains what it was when it froze regardless of the program it's over, such as the text selector.
It only happens with Silverlight and it doesn't matter which version I use.
Here's what I'm running:
Windows 7 Professional 64-bit, all of the latest updates included, 12 GB RAM & 1.5 TB HD.
Visual Studio 2010 Ultimate with all of the latest updates.
All software is legit and I've already tried removing and/or disabling just about everything that can be removed or disabled, including extensions. I've used Process Explorer from Sysinternals to kill or stop everything I can. I've also tried it on a very simple Silverlight application with nothing more than one line of code that doesn't access anything.
EDIT: Forgot to mention that I also don't have it loading symbols beyond the "Just My Code" that it normally would and I've tried every debug setting that I can think of as well. And Intellitrace is also turned off (since I do have Ultimate), but that makes no difference either.
UPDATE (11/18): It gets more and more odd. I determined that the temporary freeze doesn't occur only when Visual Studio has focus. When VS (during the super-simple Silverlight app) goes into debug mode, any keyboard access AT ALL causes the same effect. SO, it appears that it has to (in some way) be related (at least in part) to my Windows setup, contrary to my assertion in the comments, but I cannot possibly fathom how. And if other programs are doing something when it freezes, the delay is longer (which makes a certain amount of sense with the symptoms). I'm still at a complete loss.
Anyone have any ideas or see this before? It's really frustrating.
I solved the problem.
It turned out to be the LastPass toolbar. It's a very handy thing and I've used it for years without issue. Yeah, yeah, toolbars are evil, I get it. :)
Disabling it in IE fixed the problem completely. I can still use it in FF (which is my main browser anyway except for working for which I use IE) and everything works fine.
Even so, it's bizarre to me that the toolbar would only have an effect when SL debugs. I didn't have an issue with ASP.Net debugging and I didn't any issues when the SL app was actually running, only when I hit a breakpoint AND hit a key within the first 15 seconds or so.
In any case, problem solved and thanks for your suggestions.
Try changing registry setting LowLevelHooksTimeout from 5000 to something low, like 300.
It can be at
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\Control Panel\Desktop
or
HKEY_CURRENT_USER\Control Panel\Desktop
(first setting at Policy key seems to globally override user setting).

System.OutOfMemoryException and a few exceptions happen during application run, Visual Studio 2010 WPF C#

I just discovered this problem today, and I had no idea what caused this problem. My project had been developed for few months.
I have a project(solution), with several projects in there, it works well if I write and debug, by pressing F5.
The problem occur is when I press Ctrl+F5 (to skip debug mode), or run directly from double click the exe, it crashed. The errors dialogs that pop up every times are different, but OutOfMemoryException is the most frequent one.
I had checked to make sure all my projects are .Net 3.5
I put a MessageBox.Show("something") at the beginning of my main project constructor, but it never reach.
I use some registry cleaner to clean/fix my registry, scan for viruses.
I had try to read the meaning of each error and exception, but still no clue why it happen.
These are a series of screenshots if I press Ctrl + F5. (FutureGenerator is some random name I gave to my project.)
Series of screenshot if I run the app from my debug folder, FutureGenerator.exe
I suspect this is caused by framework crashed during Windows Update, but I removed those update that I performed recently, still same. The exe file works on other non development PC, but I don't want to reformat my PC or reinstall my VS, yet, because it's a painful process.
Any idea, anyone?? Million thanks.
You mention v3.5 but the very first screenshot is about v4.
Try repairing your Framework 4 and/or VS2010
I found the problem. It's actually because I added FutureGenerator.exe into Application Verifier by Microsoft. The verifier only support debugging testing.
After I removed FutureGenerator.exe from the Application Verifier, everything's ok.

Firefox/Gecko control interfering with Windows Forms key presses

Edit: In addition to the bounty, we're willing to pay $250 to have this bug fixed in the Firefox/Gecko codebase. Here is a simple test project (Visual Studio 2008 C#) that reproduces the problem.
Edit #2 we're willing to pay $600 to have this bug fixed. See above for sample project that reproduces the problem.
We have a Firefox (Gecko) ActiveX control on our C# Windows Form to display HTML.
When this Firefox ActiveX control is on our form, about 2-3% of our key presses don't make it through. Or rather, a different Windows message is sent:
We hold down the TAB key to tab through 3 regular WinForms text boxes. It will behave correctly 97% of the time. Spy++ tells us WM_KEYDOWN message is sent properly:
normal behavior http://judahhimango.com/images/normaltab.jpg
But randomly, maybe 2-3% of the time, the tab key (or other key) isn't processed right. Spy++ tells us WM_CHAR is being sent instead:
odd behavior http://judahhimango.com/images/screwytab.png
When the odd behavior occurs, either the key is not processed at all, or is processed incorrectly (such as inserting a '\t' character into a textbox that doesn't support tab characters.
This only occurs if the Firefox ActiveX control is on our form.
Our question is: does Firefox/Gecko engine install some kind of keyboard hook that might cause these side effects? Or better yet, how do we fix this problem?
The WM_CHAR message is generated by TranslateMessage call, so a good place to start looking would be the TranslateMessage calls in the Gecko source code.
In the first example code you provided the function is imported only by two libraries - mozctl.dll and xul.dll. Since you claim that the same error happens also with GeckoFX we can take mozctl.dll out of the equation. That leaves us with xul.dll, so given the Gecko source code I would suggest to look into widget\src\windows\nsToolkit.cpp. I am not sure if the code is run if the engine is embedded, but if it is then the library starts a whole new message pump in different thread, which is bound to break.
Unfortunately I can't run or compile the code on my machine (Windows 7 x64 w/o the Mozilla ActiveX control installed), so I can't verify any of this with a debugger. Hope it helps someone to track it down further.
The root problem is that when Mozilla is embedded in another application, it incorrectly pumps Windows messages when it dispatches internal events. Mozilla uses an event system to coordinate across threads or to schedule deferred processing on a thread (see nsIThread, nsIEventTarget). If you embed a web page with a lot of active XMLHTTPRequests, for example, Mozilla will use its event dispatching interface to dispatch events back to javascript and it will pump windows messages as a side effect. Once Mozilla events are fully dispatched, it goes back to the main event loop.
When Mozilla pumps windows messages, it doesn't include the extra processing done by the application's event loop - IsDialogMessage(), TranslateMessage(), PreTranslateMessage(), or any other pre-processing are skipped when Mozilla gets into this state. Symptoms therefore include tab key presses getting inserted as a character instead of being used for dialog navigation, keyboard hotkeys being sporadically ignored, or custom message pre-processing being sporadically skipped. For example, the Outlook 2007/2010 "Compose" screen sporadically loses keystrokes because it relies on custom message pre-processing to handle keyboard input.
See https://bugzilla.mozilla.org/show_bug.cgi?id=582790 for a patch that addresses the problem.
I have Snoop Free and PSM Anti-Keylogger.
One of them detected firefox trying to install a Keyboard Hook.
Mozilla/Firefox file xul.dll attempt at installing at keyboard hook.
DENIED.
I noticed that you have implemented all of the interoperability yourself. Can you try this with the GeckoFX project and see if you get the same error? I use this project at work and haven't encountered any issues yet.

Resources