I often found useful informations here, now it was time to create an account on my own and say thanks to this community for it helped me so often!
I am currently coding a game in Monogame 3.2 in Mac OSX 10.9.5 using Xamarin 5.5.4 and encountering a strange problem I've never seen before: when I press one of the arrow keys it seems as if the shift keys, both left and right, are always considered to be NOT PRESSED, even if I press them.
I checked this with these lines of code inside my game loop:
foreach (Keys key in Keyboard.GetState().GetPressedKeys()) {
Console.WriteLine (key.ToString ());
}
The output is always the same. When I press one of the shift keys only or first (and hold), I get
LeftShift
RightShift
Plus eventually the arrow keys (if shift was hold first). But when I press one of the arrow keys first and then press the shift key while one of the arrow keys is down, those two do not appear.
That's obviously a problem because my game character now cannot run when shift is pressed (at least when the arrow keys were pressed first and hold). I double checked if other keys like Z are also blocked, but it seems as if the arrow keys only block shift (but I haven't checked every key so far).
Does anyone know why this happens? I checked whether or not sticky keys is activated in Mac OSX, but it's not. Sadly, I couldn't find anything on the internet so far.
Any help is appreciated! Thanks a lot in advance!
I think MonoGame is doing a few special things to get certain keys to work on windows, might be some of these same fixes need to be done on other platforms.
Try locating the code in MonoGame that translates from OS key events to XNA key events. It is most likely where the problem is.
Also try running the most recent develop branch just to be sure it isn't a bug that was fixed in the mean time.
Related
During my search, I've seen many different versions of this question, yet somehow none of the solutions provided solved my problem.
It's really quite simple, I just want to simulate holding down a key on the keyboard through code. I want to try and make a character in a game walk forward constantly, so I just need to make a program that simulates holding down the 'W' key. I've seen a lot of people were using Windows Forms for this, I don't know if it actually is the right application but if it works I'm happy.
Just very quickly sending the key doesn't work, so simply calling SendKeys.Send('W') every 30ms does not make my character move in-game. So, what can I do to simulate holding down a key on the keyboard?
Here you go, a .Net library can simulate key press
https://inputsimulator.codeplex.com/
Edit
To get the key works, the external program must in active window, and your program need to run in background.
Windows Forms provides the SendKeys method which can simulate text
entry, but not actual key strokes. Windows Input Simulator can be used
in WPF, Windows Forms and Console Applications to synthesize or
simulate any Keyboard input including Control, Alt, Shift, Tab, Enter,
Space, Backspace, the Windows Key, Caps Lock, Num Lock, Scroll Lock,
Volume Up/Down and Mute, Web, Mail, Search, Favorites, Function Keys,
Back and Forward navigation keys, Programmable keys and any other key
defined in the Virtual Key table.
It provides a simple API to simulate
text entry, key down, key up, key press and complex modified key
strokes and chords.
I am working on a .NET program that reproduces mouse clicks however i would like to have it show that it is actually clicking,
is there a way to programatically trigger this sticky key things that shows circles around the mouse when you press shift 5 times?
Or for that matter maybe another effect just to make it clear for the user that the mouse is there and it is clicking right now. I also wish to avoid to have to actually activate sticky keys for the user since they're very annoying in my opinion.
I love you all, you make my days at work great and I take this occasion to thank you all for teaching me all the good stuff i learnt here. (:
I was hoping someone could help me with simulating a function key combination in C#, in this case FN + F4.
Here's what I'm trying to do... I have an older touchscreen netbook that I recently installed Windows 8 on. It has a swivel screen so you can fold it down and use it like a tablet. Windows 8 runs surprisingly well on it. I had a few minor issues, most of which I was able to work out, but one remains.
When you first power up the netbook or wake it from sleep, the screen is at 30% brightness, and Windows thinks that this is the max setting, so increasing the screen brightness through the normal methods does not work. On my netbook, pressing FN + F4, restores the screen to full brightness. This is a minor annoyance though, because I have to swivel the screen back and forth to fix the brightness using the physical keyboard, when I'd like to just leave it in the tablet position and minimize wear and tear.
What I'd like to do is write a little application that runs on start up, and simulates the function key combination, so the brightness is restored automatically. Any suggestions would be greatly appreciated. Thanks.
The Fn key is not a key that is sent from the keyboard to the computer. It is actually used to change the meaning of keys on the keyboard (such that the keyboard sends different scancodes when the key is pressed with Fn held down).
You should be able to easily write a simple Windows Forms program that listens to key presses and shows you what has been received. Register for the KeyDown event. The KeyEventArgs your handler receives has various properties that you can inspect to see what is being received.
The FN key isn't a real keyboard key like the other modifiers (shift, alt, ctrl) nor is it a function key like the F1 - F12. The FN key is a hardware only key that simply tells the hardware to send a different keystroke while the FN key is being pressed.
So, you are going to have to adjust the brightness manually like "m-y" stated in the comments or through some other mechanism.
Reference Link.
We are developing a hot key for one of our application.
A key combination that is
easy to remember
easy to press (especially for people
with small fingers)
certainly not ctrl-alt-del ;)
Which key combination do you suggest for a hot-key?
EDIT: Please suggest any specific character instead of generic ones.
How about Ctrl + ?
The Ctrl key is right next to the ? key. Also the question mark makes sense since none of us has any idea what the hot key is supposed to do.
It should depend on the keyboard layout, qwerty or dvorak and language configuration, of your main user. It also depends on the usage of the application when the user should trigger it. Is s/he using the mouse or the keyboard for instance.
On the topic of remembering a hotkey, using Ctrl+S for a save action or Ctrl+O for open is pretty much standard for GUI applications nowadays, so users would remember those. If the shortcut is used many times or is important in the application the user will remember it, even if it's as silly as pressing Shift 5 times in a row.
If it's not used often, it should be presented to the user in a way that it does not interrupt the work flow, as a shortcut is often displayed in a menu item for instance.
And as a final note, don't make a keyboard shortcut to remove your changes and place it next to your Save shortcut. :-)
What does the hotkey do?
Any combination with Ctrl or Alt will do, excluding the ones used by the windows UI( Ctrl+A for select-all, Ctrl+S for save, etc)
Give us more info.
Scroll Lock - it's not being used for anything else. But seriously, it will only be easy to remember if it has something to do with the application or people use it all the time.
Jay Riggs said:
How about Control + ?
The Ctrl key is right next to the ? key. [...]
That's how it is on a American/British (I don't know how these layouts are called.) keyboard. But on German/French etc keyboards ? is right next to 0. So it's not the best choice when you are planning to publish your application in several countries.
I think it's not that easy to decide, what a good hot key is as long you doesn't give us a some more details.
I am working on an application that has multiple dockable panels like Visual Studio. At some point the accelerator keys for the menu stopped working. They sometimes work depending on what panel is currently active. When they are not working pressing the alt key sets the focus to the menu bar and shows the underscores under the appropriate characters, but pressing any of the characters does not show the menu.
I've been banging my head against this for a little bit and am wondering if there is an easier way to find out what is happening to those key presses.
The first place to look is in any key press handlers within your code. I would set a breakpoint in all of those and see if those event handlers are stopping the key press from being bubbled up.
I found that there was a control that had overridden Control.ProcessMnemonic(). There was a logic error that was returning true when it should have been returning false.
Not exactly an easy error to find without spending a lot if time.