This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi all:
I am trying to get the scancode of the characters that are entered in a LineEdit. I am using findscancodefrom_string to print the code of the letters or puncutation symbols ("," ".") entered.

For simplicity, I have created a scene with just a LineEdit and a Label which changes its text with the text entered via a signal from the LineEdit, while the console shows its scancode.

In the following code you may check how if you write an "a" in the LineEdit, it works perfectly showing a "a" and prints its code "65" , but if you write a "," it shows that "," but code "0". Same with "(", "." and on... Any ideas?

extends Node2D


func _ready():
    pass # Replace with function body.


func _on_LineEdit_text_entered(new_text):
    $"Label".set_text(new_text)
    print(new_text)
    var scan = OS.find_scancode_from_string(new_text)
    print(scan)

in Engine by (16 points)

1 Answer

+1 vote

Are you really looking for a scancodeor do you instead want the ASCII value for the character in question? It looks like the find_scancode_from_string function you're using would require the string Comma (for example) to return the expected value of 44.

If you just want the ASCII value for a given character, maybe you want the ord function instead. Here's an example:

print(ord("A")) # 65
print(ord(",")) # 44

Though, do be aware that the ASCII value for lower-case and upper-case letters is different. For example, a will return 97 while A will return 65.

by (22,704 points)
edited by

Thanks so much @jgodfrey, I didn't know there was an opposite to char(). That made it!
Again, thanks a lot.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.