Skip to content

[p5.js 2.0 RFC Proposal]: expand keyIsDown() to work with characters as arguments #6798

@kjhollen

Description

@kjhollen

Increasing access

Having some symmetry where you can also do:

keyIsDown('a');

would be useful for teaching beginners.

Which types of changes would be made?

  • Breaking change (Add-on libraries or sketches will work differently even if their code stays the same.)
  • Systemic change (Many features or contributor workflows will be affected.)
  • Overdue change (Modifications will be made that have been desirable for a long time.)
  • Unsure (The community can help to determine the type of change.)

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

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:

keyIsDown(LEFT_ARROW);
keyIsDown(ENTER);

but if they want to check if an alphanumeric key is down, the code is different:

keyIsPressed && key == 'a'

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:

keyIsDown('a');

Pros (updated based on community comments)

Example list:

  • Consistency: This proposal increases API consistency by giving users a way to enter the name of an alphanumeric key for keyIsDown();
  • can use keyIsDown() without having to look up keycodes

Cons (updated based on community comments)

  • would this be confusing for cases like 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

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Completed

Relationships

None yet

Development

No branches or pull requests

Issue actions