-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Language Idea] Add pressed for binding keyboard events (#3483)
Makes it possible to test if a certain keyboard button is pressed. **Description** Fixes #3337, #3413, #3406 and #3546. - Adds the **ifpressed** grammer rule, for level 5 and upwards - Adds the **UsesPygame** Transformer - Uses the PyGame library - #3335 **How to test** Open up level 5 and use the following snippet ```python if x is pressed print 'Ouch!' else print 'Hi!' ``` This will map the keyboard press _x_ to print 'Ouch' and any other to 'Hi!'. You can change _x_ by any Latin letter or one digit number. After running the code, if you press _x_ it should output 'Ouch!'. The program should stop executing after the output. ![Hedy_—_Mozilla_Firefox_2022-10-25_11-50-32_AdobeExpress(1)](https://user-images.githubusercontent.com/48225550/197743506-64076374-8110-4ee8-ac9f-52eba1883388.gif) Next, Open up level 8 and use the following snippet ```python if a is pressed print 'Ouch!' else print 'Hi!' ``` This is necessary because in level 8, inline if statements are not allowed anymore. The result should be the same as in level 5. Try out some turtle commands as well! ```python if x is pressed forward 50 else turn 90 ``` It should get the turtle moving or turning. **:exclamation: Important Comments** - The keyword _pressed_ is currently not highlighted. Essentially pressed is a state (for kids: "a special variable") and not a command. I think it would be cool to give these "special variables" a different color (blue maybe?).
- Loading branch information
Showing
29 changed files
with
1,515 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,5 @@ length: length | |
9: '9' | ||
0: '0' | ||
comma: ',' | ||
quote: "'" | ||
quote: "'" | ||
pressed: pressed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,4 @@ length: lengte | |
0: '0' | ||
comma: ',' | ||
quote: "'" | ||
pressed: ingedrukt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.