Skip to content

keyTyped function ignores last key typed #7805

@quarks

Description

@quarks

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)

p5.js version

1.11.5 & 2.0.1

Web browser and version

No response

Operating system

Mac OSX 15.4.1

Steps to reproduce this

Steps:

Run the code below and type several characters. They will be displayed but it will ignore a key if it has the same ASCII code as the previous key typed.
For instance type abcdddddefgGdh will display
a b c d e f g G d h

Note that only the first d is displayed, repeats are ignored but can be displayed later if a different key is typed first.

Snippet:

let s = '>';

function setup() {
  createCanvas(600, 300);
  textSize(16);
}

function keyTyped(){
  s = s + ' ' + key;
}

function draw() {
  background(240); noStroke();  fill(0, 0, 160);
  text(s, 10, 10, width - 20, height - 20);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions