Cyron43 Posted October 12, 2015 Share Posted October 12, 2015 (edited) Hi guys,there are times when I face a certain problem when I create mods. I set a specific key for an action (let's say Ctrl+T) and then when I test my mod I get a response from another mod written by someone else. His description claims one has to press T. Yes, just T and not Ctrl+T. There is just one keyboard but a gazillion mods and so I think it's about time to teach you how to do it right, for the sake of the modder community. Here is a typical KeyDown event handler: private void OnKeyDown(object sender, KeyEventArgs e){ if(e.KeyCode == Keys.T) { // do something... }} Do your KeyDown handlers look like this (or KeyUp handler, that doesn't matter)? Then you're doing it wrong! This method doesn't care if you press either Ctrl, Shift and/or Alt in addition.Here is how to do it right: private void OnKeyDown(object sender, KeyEventArgs e){ if(!e.Alt && !e.Control && e.KeyCode == Keys.T && !e.Shift) { // do something... }} This assures your mod reacts only on T but not to any other combination with T. So the combinations are still free for other mods.Another example. Let's say you want to handle Ctrl+Shift+X (watch closely for the exclamation marks). private void OnKeyDown(object sender, KeyEventArgs e){ if(!e.Alt && e.Control && e.KeyCode == Keys.X && e.Shift) { // do something... }} Edited December 13, 2015 by Cyron43 MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
MrGTAmodsgerman Posted October 15, 2015 Share Posted October 15, 2015 Danke, eine Frage, ist die Reihenfolge egal? Also z.B private void OnKeyDown(object sender, KeyEventArgs e){ if(!e.Alt && e.Control && e.Shift) && e.KeyCode == Keys.X { // do something... }} ? Link to comment Share on other sites More sharing options...
Cyron43 Posted October 15, 2015 Author Share Posted October 15, 2015 (edited) Danke, eine Frage, ist die Reihenfolge egal? Also z.B private void OnKeyDown(object sender, KeyEventArgs e){ if(!e.Alt && e.Control && e.Shift) && e.KeyCode == Keys.X { // do something... }} ? Ja, das ist hier egal. Edited October 15, 2015 by Cyron43 MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...