Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Letter Case Input and Detection
- PokePika__10339__
-
Scratcher
500+ posts
Letter Case Input and Detection
How can I detect key input AND letter case? I've tried using sprite costumes but it only returns lowercase, never uppercase. Is this not possible using costumes?
when [any v] key pressed
set [Output key v] to ()
if <key [any v] pressed?> then
switch costume to [1 v]
repeat (110)
if <key (costume [name v]::looks) pressed> then
set [Output key v] to (costume [name v]::looks)
stop [this script v]
else
next costume
end
end
end
- MultiTasker801
-
Scratcher
100+ posts
Letter Case Input and Detection
i believe the problem is that the key pressed block is NOT case-sensitive. i'm not sure if it's actually possible to get case-sensitive inputs in scratch, barring usage of the ask block, which is obviously not ideal. there's also no method of detecting the shift key so you wouldn't be able to pick up capitals that way either.
- PokePika__10339__
-
Scratcher
500+ posts
Letter Case Input and Detection
i believe the problem is that the key pressed block is NOT case-sensitive. i'm not sure if it's actually possible to get case-sensitive inputs in scratch, barring usage of the ask block, which is obviously not ideal. there's also no method of detecting the shift key so you wouldn't be able to pick up capitals that way either.Okay. I'll look more into it but you're probably right.
- deck26
-
Scratcher
1000+ posts
Letter Case Input and Detection
But if you can detect a letter and detect if it is lower case then if it is a letter and not lower case you can detect upper case! The method using costumes can easily be modified to detect upper case instead - instead of having a set of costumes abc… you have costumes ABC…..
Really don't see the problem.
Really don't see the problem.
- MultiTasker801
-
Scratcher
100+ posts
Letter Case Input and Detection
Really don't see the problem.even if you can get specific case letters, you run into a problem when you try to detect them as inputs because none of the input detecting blocks:
when [... v] key pressedare case sensitive. case sensitive input detection in vanilla scratch is impossible. case closed
<key [... v] pressed?>
- Scratch-Minion
-
Scratcher
1000+ posts
Letter Case Input and Detection
Scratch costume names are case sensitive, but the <key … pressed> block is not case sensitive.
If you detect <key costume name pressed>, you should then switch to that costume!
It will switch to the costume name with the correct case even though the key pressed may have detected the other case!
*** EDIT *** CODE BELOW IS WRONG! *** I WILL FIX IT IN ANOTHER POST ***
*** IT WAS LATE WHEN I WROTE THIS ***
You can fix the code with a single additional line:
If you detect <key costume name pressed>, you should then switch to that costume!
It will switch to the costume name with the correct case even though the key pressed may have detected the other case!
*** EDIT *** CODE BELOW IS WRONG! *** I WILL FIX IT IN ANOTHER POST ***
*** IT WAS LATE WHEN I WROTE THIS ***
You can fix the code with a single additional line:
when [any v] key pressed
set [Output key v] to ()
if <key [any v] pressed?> then
switch costume to [1 v]
repeat (110)
if <key (costume [name v]::looks) pressed> then // this detects the letter whether the case matches or not
switch costume to (costume name::looks) // this switches to the letter costume of the correct case
set [Output key v] to (costume [name v]::looks)
stop [this script v]
else
next costume
end
end
end
Last edited by Scratch-Minion (Dec. 1, 2023 18:39:36)
- PokePika__10339__
-
Scratcher
500+ posts
Letter Case Input and Detection
Scratch costume names are case sensitive, but the <key … pressed> block is not case sensitive.I'll try this out!
If you detect <key costume name pressed>, you should then switch to that costume!
It will switch to the costume name with the correct case even though the key pressed may have detected the other case!
You can fix the code with a single additional line:when [any v] key pressed
set [Output key v] to ()
if <key [any v] pressed?> then
switch costume to [1 v]
repeat (110)
if <key (costume [name v]::looks) pressed> then // this detects the letter whether the case matches or not
switch costume to (costume name::looks) // this switches to the letter costume of the correct case
set [Output key v] to (costume [name v]::looks)
stop [this script v]
else
next costume
end
end
end
- Scratch-Minion
-
Scratcher
1000+ posts
Letter Case Input and Detection
Scratch costume names are case sensitive, but the <key … pressed> block is not case sensitive.
If you detect <key costume name pressed>, you should then switch to that costume!
It will switch to the costume name with the correct case even though the key pressed may have detected the other case!
*** Edit: I MUST HAVE HALF ASLEEP.
THE CODE BELOW ALSO DOESN'T WORK.
Create a variable Keys with the single letter names of your 110 costumes:
eg.
then:
There is one more check that you should do!
It may be that the “any” key pressed was not a letter or character key but <Enter>, an <arrow> key etc.
If the code exits the repeat loop without having found a printable character (ie. “stop this script” will not have happened) then you should add code after the repeat loop. Note that your variable “Output key” will still be empty.
Note that the script under “when any key pressed” is inside a “run without screen refresh” custom block so it all runs immediately.
* Edit: I have added the custom block now rather than just suggesting it..
If you detect <key costume name pressed>, you should then switch to that costume!
It will switch to the costume name with the correct case even though the key pressed may have detected the other case!
*** Edit: I MUST HAVE HALF ASLEEP.
THE CODE BELOW ALSO DOESN'T WORK.
Create a variable Keys with the single letter names of your 110 costumes:
eg.
set [Letters v] to [abc...xyzABC...XYZ0123...]
then:
when [any v] key pressed
Get Key Pressed
define Get Key Pressed
set [Output key v] to ()
set [n v] to [1]
repeat (110)
switch costume to (join (letter (n) of (Letters)) []) // this switches to the letter costume of the correct case
if <key (costume [name v]::looks) pressed> then // this detects the letter whether the case matches or not
set [Output key v] to (costume [name v]::looks)
stop [this script v]
else
change [n v] by (1)
end
end
There is one more check that you should do!
It may be that the “any” key pressed was not a letter or character key but <Enter>, an <arrow> key etc.
If the code exits the repeat loop without having found a printable character (ie. “stop this script” will not have happened) then you should add code after the repeat loop. Note that your variable “Output key” will still be empty.
Note that the script under “when any key pressed” is inside a “run without screen refresh” custom block so it all runs immediately.
* Edit: I have added the custom block now rather than just suggesting it..
Last edited by Scratch-Minion (Dec. 5, 2023 23:37:05)
- EDawg2011
-
Scratcher
1000+ posts
Letter Case Input and Detection
i believe the problem is that the key pressed block is NOT case-sensitive. i'm not sure if it's actually possible to get case-sensitive inputs in scratch, barring usage of the ask block, which is obviously not ideal. there's also no method of detecting the shift key so you wouldn't be able to pick up capitals that way either.You can detect the shift key like this.

<key [(join [] [shift]) v] pressed?>
(join [] [shift])
<key [ v] pressed?>Another edit: I got so ninja'd.
Last edited by EDawg2011 (Dec. 1, 2023 21:36:53)
- PokePika__10339__
-
Scratcher
500+ posts
Letter Case Input and Detection
Actually, shifts can't even be detecting using this unless you're on Turbowarp or some other Scratch modi believe the problem is that the key pressed block is NOT case-sensitive. i'm not sure if it's actually possible to get case-sensitive inputs in scratch, barring usage of the ask block, which is obviously not ideal. there's also no method of detecting the shift key so you wouldn't be able to pick up capitals that way either.You can detect the shift key like this.<key [(join [] [shift]) v] pressed?>(join [] [shift])<key [ v] pressed?>Another edit: I got so ninja'd.
Scratch costume names are case sensitive, but the <key … pressed> block is not case sensitive.I already had it in a run without screen refresh block (but thanks for that), and I know it runs even when the key isn't a letter. I've already been adding keys such as ‘Enter’, ‘Backspace’/'Delete' and the arrow keys. Thanks for the help!
If you detect <key costume name pressed>, you should then switch to that costume!
It will switch to the costume name with the correct case even though the key pressed may have detected the other case!
Below is my fixed fix for the code:
Create a variable Keys with the single letter names of your 110 costumes:
eg.set [Letters v] to [abc...xyzABC...XYZ0123...]
then:when [any v] key pressed
Get Key Pressed
define Get Key Pressed
set [Output key v] to ()
set [n v] to [1]
repeat (110)
switch costume to (join (letter (n) of (Letters)) []) // this switches to the letter costume of the correct case
if <key (costume [name v]::looks) pressed> then // this detects the letter whether the case matches or not
set [Output key v] to (costume [name v]::looks)
stop [this script v]
else
change [n v] by (1)
end
end
There is one more check that you should do!
It may be that the “any” key pressed was not a letter or character key but <Enter>, an <arrow> key etc.
If the code exits the repeat loop without having found a printable character (ie. “stop this script” will not have happened) then you should add code after the repeat loop. Note that your variable “Output key” will still be empty.
Note that the script under “when any key pressed” is inside a “run without screen refresh” custom block so it all runs immediately.
* Edit: I have added the custom block now rather than just suggesting it..
- 10goto10
-
Scratcher
1000+ posts
Letter Case Input and Detection
I don’t understand the solutions here since the
However, and this is an Ugly solution but you might have to borrow the old technique from a TRS-80 (model 1). The user had to enter a special character to indicate that the next letter was a capital letter.
switch costume to [A v]and
<key [(costume name) v] pressed?>
switch costume to [a v]do the same thing since the key block is case insensitive. I’ve tried this in a small test case.
<key [(costume name) v] pressed?>
However, and this is an Ugly solution but you might have to borrow the old technique from a TRS-80 (model 1). The user had to enter a special character to indicate that the next letter was a capital letter.
Last edited by 10goto10 (Dec. 2, 2023 16:32:24)
- Scratch-Minion
-
Scratcher
1000+ posts
Letter Case Input and Detection
I don’t understand the solutions here since theswitch costume to [A v]and
<key [(costume name) v] pressed?>switch costume to [a v]do the same thing since the key block is case insensitive. I’ve tried this in a small test case.
<key [(costume name) v] pressed?>
However, and this is an Ugly solution but you might have to borrow the old technique from a TRS-80 (model 1). The user had to enter a special character to indicate that the next letter was a capital letter.
In Scratch a sprite can have 2 different costumes named A and a.
The “switch costume to …” block is case sensitive and will switch to A or a as specified.
- MultiTasker801
-
Scratcher
100+ posts
Letter Case Input and Detection
… but the block that actually indicates whether the button is pressed is case-insensitive so it doesn't matter what the input is and you'll always get something case-insensitive out the other end. have you considered, like, actually implementing your suggestions and seeing if they work? lolI don’t understand the solutions here since theswitch costume to [A v]and
<key [(costume name) v] pressed?>switch costume to [a v]do the same thing since the key block is case insensitive. I’ve tried this in a small test case.
<key [(costume name) v] pressed?>
However, and this is an Ugly solution but you might have to borrow the old technique from a TRS-80 (model 1). The user had to enter a special character to indicate that the next letter was a capital letter.
In Scratch a sprite can have 2 different costumes named A and a.
The “switch costume to …” block is case sensitive and will switch to A or a as specified.
- Scratch-Minion
-
Scratcher
1000+ posts
Letter Case Input and Detection
… but the block that actually indicates whether the button is pressed is case-insensitive so it doesn't matter what the input is and you'll always get something case-insensitive out the other end. have you considered, like, actually implementing your suggestions and seeing if they work? lolI don’t understand the solutions here since theswitch costume to [A v]and
<key [(costume name) v] pressed?>switch costume to [a v]do the same thing since the key block is case insensitive. I’ve tried this in a small test case.
<key [(costume name) v] pressed?>
However, and this is an Ugly solution but you might have to borrow the old technique from a TRS-80 (model 1). The user had to enter a special character to indicate that the next letter was a capital letter.
In Scratch a sprite can have 2 different costumes named A and a.
The “switch costume to …” block is case sensitive and will switch to A or a as specified.
Yes, I have tested this.
I suggest you make a project with 2 costumes A and a.
“Switch costume to A” will always switch to costume A
“Switch costume to a” will always switch to costume a
The “key .. pressed” block is not case sensitive and the blocks below work the same, each detecting both A and a.
<key [A] pressed?>
<key [a] pressed?>
- MultiTasker801
-
Scratcher
100+ posts
Letter Case Input and Detection
you are demonstrating great knowledge of what you're talking about, but you are not at all helping with the conversation. all you've done is say “costumes are case sensitive” while providing no solution to the question of case-sensitive input detection. it's like if you were having a conversation about which tool is best for accurate metal-working and i came along and repeatedly remarked about how copper is conductive. like that's great dude but nobody asked and nothing of value has been added to the conversation. it's particularly ridiculous because OP has already demonstrated that they are ALSO aware that costume names have unique properties. you've made up an unrelated question, answered it, and gotten defensive when it was pointed out.… but the block that actually indicates whether the button is pressed is case-insensitive so it doesn't matter what the input is and you'll always get something case-insensitive out the other end. have you considered, like, actually implementing your suggestions and seeing if they work? lol//removed text, this thread is now getting rather long//
In Scratch a sprite can have 2 different costumes named A and a.
The “switch costume to …” block is case sensitive and will switch to A or a as specified.
Yes, I have tested this.
I suggest you make a project with 2 costumes A and a.
“Switch costume to A” will always switch to costume A
“Switch costume to a” will always switch to costume a
The “key .. pressed” block is not case sensitive and the blocks below work the same, each detecting both A and a.<key [A] pressed?>
<key [a] pressed?>

- deck26
-
Scratcher
1000+ posts
Letter Case Input and Detection
OK, the issue here is the use of the keypressed method of input.
If you use the ask/answer method of input you can easily detect upper or lower case but that's because we actually have the input and it's just a case of how we use it. So saying ‘if answer = a’ still doesn't distingusih between A and a but if we use tricks like the costume name being case sensitive we can distinguish between them. (This is because answer actually contains the input as typed so will contain a or A.)
I think both @Scratch-Minion and I overlooked this essential difference but apologies to @Scratch-Minion if they disagree.
Other than using the ask/answer method I can see no way to do this.
<key [A v] pressed?>will both detect A or a and it doesn't matter whether you refer to a/A as hardcoded text or costume names, I don't think you can detect the difference,
<key [A v] pressed?>
If you use the ask/answer method of input you can easily detect upper or lower case but that's because we actually have the input and it's just a case of how we use it. So saying ‘if answer = a’ still doesn't distingusih between A and a but if we use tricks like the costume name being case sensitive we can distinguish between them. (This is because answer actually contains the input as typed so will contain a or A.)
I think both @Scratch-Minion and I overlooked this essential difference but apologies to @Scratch-Minion if they disagree.
Other than using the ask/answer method I can see no way to do this.
- BigSus2
-
Scratcher
86 posts
Letter Case Input and Detection
OK, the issue here is the use of the keypressed method of input.One thing you might be able to do for a sort of “sub shift” button is repurpose the ~ key as a shift. As using the join () () technique works with the ~ button. From there its pretty easy to differentiate shift presses.<key [A v] pressed?>will both detect A or a and it doesn't matter whether you refer to a/A as hardcoded text or costume names, I don't think you can detect the difference,
<key [A v] pressed?>
If you use the ask/answer method of input you can easily detect upper or lower case but that's because we actually have the input and it's just a case of how we use it. So saying ‘if answer = a’ still doesn't distingusih between A and a but if we use tricks like the costume name being case sensitive we can distinguish between them. (This is because answer actually contains the input as typed so will contain a or A.)
I think both @Scratch-Minion and I overlooked this essential difference but apologies to @Scratch-Minion if they disagree.
Other than using the ask/answer method I can see no way to do this.
- PokePika__10339__
-
Scratcher
500+ posts
Letter Case Input and Detection
You don't need to detect shift since you can already detect keys such as ~ or A. You just need to be able to distinguish between capital and lowercase.OK, the issue here is the use of the keypressed method of input.One thing you might be able to do for a sort of “sub shift” button is repurpose the ~ key as a shift. As using the join () () technique works with the ~ button. From there its pretty easy to differentiate shift presses.<key [A v] pressed?>will both detect A or a and it doesn't matter whether you refer to a/A as hardcoded text or costume names, I don't think you can detect the difference,
<key [A v] pressed?>
If you use the ask/answer method of input you can easily detect upper or lower case but that's because we actually have the input and it's just a case of how we use it. So saying ‘if answer = a’ still doesn't distingusih between A and a but if we use tricks like the costume name being case sensitive we can distinguish between them. (This is because answer actually contains the input as typed so will contain a or A.)
I think both @Scratch-Minion and I overlooked this essential difference but apologies to @Scratch-Minion if they disagree.
Other than using the ask/answer method I can see no way to do this.
- PokePika__10339__
-
Scratcher
500+ posts
Letter Case Input and Detection
~long quote snip~-explanation on keys--snip x2-//removed text, this thread is now getting rather long//
In Scratch a sprite can have 2 different costumes named A and a.
The “switch costume to …” block is case sensitive and will switch to A or a as specified.<key [A] pressed?>
<key [a] pressed?>
OK, the issue here is the use of the keypressed method of input.They're saying that using the costume in the key pressed block you can detect case sensitive keys since the costume block is also case sensitive. If you doubt this, try testing it yourself.<key [A v] pressed?>will both detect A or a and it doesn't matter whether you refer to a/A as hardcoded text or costume names, I don't think you can detect the difference,
<key [A v] pressed?>
If you use the ask/answer method of input you can easily detect upper or lower case but that's because we actually have the input and it's just a case of how we use it. So saying ‘if answer = a’ still doesn't distingusih between A and a but if we use tricks like the costume name being case sensitive we can distinguish between them. (This is because answer actually contains the input as typed so will contain a or A.)
I think both @Scratch-Minion and I overlooked this essential difference but apologies to @Scratch-Minion if they disagree.
Other than using the ask/answer method I can see no way to do this.
Last edited by PokePika__10339__ (Dec. 4, 2023 16:20:37)
- BigSus2
-
Scratcher
86 posts
Letter Case Input and Detection
Yeah I know, I simply misread what the other guy was saying.~long quote snip~-explanation on keys--snip x2-//removed text, this thread is now getting rather long//
In Scratch a sprite can have 2 different costumes named A and a.
The “switch costume to …” block is case sensitive and will switch to A or a as specified.<key [A] pressed?>
<key [a] pressed?>OK, the issue here is the use of the keypressed method of input.They're saying that using the costume in the key pressed block you can detect case sensitive keys since the costume block is also case sensitive. If you doubt this, try testing it yourself.<key [A v] pressed?>will both detect A or a and it doesn't matter whether you refer to a/A as hardcoded text or costume names, I don't think you can detect the difference,
<key [A v] pressed?>
If you use the ask/answer method of input you can easily detect upper or lower case but that's because we actually have the input and it's just a case of how we use it. So saying ‘if answer = a’ still doesn't distingusih between A and a but if we use tricks like the costume name being case sensitive we can distinguish between them. (This is because answer actually contains the input as typed so will contain a or A.)
I think both @Scratch-Minion and I overlooked this essential difference but apologies to @Scratch-Minion if they disagree.
Other than using the ask/answer method I can see no way to do this.
- Discussion Forums
- » Help with Scripts
-
» Letter Case Input and Detection