- Home /
Can § be used as input?
Hey,
I try to use "§"(under"Esc", next to "1") key as input, so player could stop "game time", not "Unity time". Meaning that by pressing "§" player could toggle, for example some scripts but keep Unity running.
Yes, I could use some other key on keyboard but "§,1,2,3" seems most logical: § = stop, 1 = slow, 2 = medium, 3 = fast.
Here is something that I tried:
void Update () {
if (Input.GetKeyDown(KeyCode.§)){
Debug.Log ("§ pressed");
}
if (Input.GetAxis ("§") != 0){
Debug.Log ("§ axis");
}
}
First problem is "KeyCode.§". I get Parser Error: Unexpected character "§".
Well I made new axis. Edit - Project Settings -Input.
Now I try "§" key as any input (negative, positive, alternative). I get "§" there but when I click something else it disappears.
Is "§" key hard coded in way that it can´t be input?
If I can get at least one Debug.Log message I could continue.
Any help is welcome.
Thanks ahead community.
Ps. Tell me if this should be some were else that here in Ask&Answer
Here is my feedback suggestion to Unity: (sharing should help)
https://feedback.unity3d.com/suggestions/more-keyboard-layouts-to-input-mapping
Difference between standard PC QWERTY and PC QWERTY Nordic keyboards, most likely.
Hoping that Unity could have feature/asset that we could map different keyboard -layouts if there is conflict on standard mapping.
I can do work around using "Esc" as pause and then let player chose for going menu or continue or design-mode so on and so on.
Answer by tanoshimi · Jan 28, 2016 at 02:35 PM
Can't say I've ever seen that symbol on a keyboard before, but no, it's not a recognised input key. Here's the supported values -
Thanks for link. It will help people with similar problem. I checked that out already before I send question. But good call.
I realize that my keyboard is "PC QWERTY Nordic" so this might be just that. By "Nordic" I mean that we have "A-Z and ÅÄÖ"letters so my keyboard is slightly different that standard "PC QWERTY" but it is still fairly commonly used in Finland, Sweden, Norway, Denmark, Iceland and rarely used around world.
Could Unity have feature/asset for cross-keyboard mapping? $$anonymous$$eaning that in Unity editor you could see different type of keyboards and map keys based on those. $$anonymous$$ap input keys for each type of keyboard. Simple, visual and easy.
What value do you get from inputString on pressing the key? I suspect not anything as it's a non-ascii character, but worth a try?
http://docs.unity3d.com/ScriptReference/Input-inputString.html
void Update () { foreach (char c in Input.inputString) { Debug.Log (c); } }
Console prints "§"-mark as well as any other character, letter, number.
Hmm... is this red from Win / Operating System.
In that case you've got a solution, right?
ins$$anonymous$$d of:
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.§)){
Debug.Log ("§ pressed");
}
you use:
if(Input.inputString == "§")){
Debug.Log("§ pressed");
}
Well yeah, it works. Thanks! But if player holds §-key down:
{if (Input.inputString == "§" && bool) { bool = false;}
else if (Input.inputString == "§" && !bool){ bool = true;}}
Now it toggles every frame, pause or unpause, if § is pressed. I didn´t find similar to $$anonymous$$eyDown version for inputString. Can inputString be made "manually" work only for one frame? even if key is holded down?
Going here now.
string lastPressed;
void Start(){
string lastPressed = "";
}
void Update() {
if(Input.inputString == "§" && lastPressed != "§")){ Debug.Log ("§ pressed this frame"); }
else { Debug.Log ("Not § pressed this frame"); }
lastPressed = Input.inputString;
}
Not pressing §, console = Not § pressed this frame; Ok
Pressing §, console = Both messages game; not Ok
I tried with more experienced college to solve this issue. No solid fix or work around found. If using different key is not option.
Answer by FortisVenaliter · Jan 28, 2016 at 04:09 PM
Looks like that symbol is only available in European Macs, so Unity does not have native support for it. You might try the standard PC QWERTY equivalent, (which is '`' or '~') and see if Unity recognizes it as such.
Thanks for your time and effort. I commented to tanoshimi answer and I hope you could check that out as well, mainly for more info.
I thank for equivalents, '`' is under Shift+` and '~' is under Ctrl+Alt+¨.
$$anonymous$$y keyboard is "PC QWERTY Nordic" model, extra ÅÄÖ-letters, so there is some differences to standard PC QWERTY.
Could Unity have feature/asset for cross-keyboard mapping? $$anonymous$$eaning that in Unity editor you could see different type of keyboards and map keys based on those. $$anonymous$$ap input keys for each type of keyboard. Simple, visual and easy.
Answer by ForbiddenSoul · Jan 29, 2016 at 08:55 AM
The "§" symbol is a "`" symbol on every PC keyboard I've seen. They key that usually opens up the console for games. Anyways you can probably use it with KeyCode.BackQuote
Input.GetKeyDown(KeyCode.BackQuote)
Sadly not getting response. Not on § or Shift+´ or ´. I also tried all combination I came up with. But thanks for your time and effort.
In example GTAV "§" does open console. So you got that right.
Going to try $$anonymous$$eyCode."different symbols".
I press "´" nothing happens before I press it again, now there is two of them. Or once Quote and then "e" or "t" I get "é" or "´t".
Hmm... if you could press Quote or BackQuote once in Text field like this comment, do you get nothing or one Quote? Possible feature on Nordic keyboard?