Open kjhollen opened 5 months ago
Hi, I'd like to work on this, thank you!
Hi, I'd like to work on this, thank you! I think I solve it.
Sorry I don't know if this is a right pin @limzykenneth, I saw that you are under I/O and I am currently working on the implementation for this. It seems to be a conflict for the const "LEFT_ARROW" with the purposed solutions of using String as a input. I can propose 2 solutions.
keyIsDown
to allow both type number
and string
for the code parameter (this allows to keep the constants DOWN_ARROW
, RIGHT_ARROW
, etc."DOWN_ARROW"
, "LEFT_ARROW"
, etc instead (and then maybe delete the constants for the arrow and other escape keys?).Hey,
I made a working draft PR above for keyIsDown()
to accept alphanumeric String params such as 'w'
or 'W'
. Regarding the confusing case of the int 4
versus string '4'
, this implementation includes both where the string parameter e.g. '4'
reflects the ASCII value of '4'
while the int parameter e.g. 4
reflects the ASCII code 4
.
The documentation is also updated to reflect the changes with examples now included for the new changes.
Let me know if any unit tests are necessary for these changes (based on the current tests for keyIsDown()
I do not think we need to add any additional tests)
Feedback is much appreciated :)
@wwwld1 I think keyIsDown
should also accept keys with names longer than one character such as "arrowUp", "command", and "space"
Increasing access
Having some symmetry where you can also do:
would be useful for teaching beginners.
Which types of changes would be made?
Most appropriate sub-area of p5.js?
What's the problem?
keyIsDown()
currently only works with keycodes. Sometimes this is confusing for my students, because they can use this for things like:but if they want to check if an alphanumeric key is down, the code is different:
What's the solution?
keyIsDown()
would need an addition that checks the type of the argument and allows passing text/characters. This means p5.js would have some symmetry where you can also do:Pros (updated based on community comments)
Example list:
keyIsDown()
;keyIsDown()
without having to look up keycodesCons (updated based on community comments)
keyIsDown(4)
where the user might mean the number 4? (note that 3, 8, and 9 are valid keycodes, so we can't just allow all numbers < 10)Proposal status
Under review