The keyPressed() function is called once every time a key is pressed. The key that was pressed is stored in the key variable.
For non-ASCII keys, use the keyCode variable. The keys included in the ASCII specification (BACKSPACE, TAB, ENTER, RETURN, ESC, and DELETE) do not require checking to see if the key is coded; for those keys, you should simply use the key variable directly (and not keyCode). If you're making cross-platform projects, note that the ENTER key is commonly used on PCs and Unix, while the RETURN key is used on Macs. Make sure your program will work on all platforms by checking for both ENTER and RETURN.
Because of how operating systems handle key repeats, holding down a key may cause multiple calls to keyPressed(). The rate of repeat is set by the operating system, and may be configured differently on each computer.
Note that there is a similarly named boolean variable called keyPressed. See its reference page for more information.
Mouse and keyboard events only work when a program has draw(). Without draw(), the code is only run once and then stops listening for events.
ฟังก์ชัน keypressed() เรียกว่าทุกๆเวลาคีย์ถูกกด คีย์ที่ถูกกดจะถูกเก็บไว้ในตัวแปรที่สำคัญ
ไม่ใช่กุญแจไขระหัส ASCII ใช้ตัวแปร กุญแจอยู่ใน ASCII สเปค ( BACKSPACE , แท็บ , ระบุ , ผลตอบแทน , ESC , และลบ ) ไม่จําเป็นต้องมีการตรวจสอบเพื่อดูว่าคีย์เป็นรหัส สำหรับคีย์นั้นคุณก็ควรจะใช้ตัวแปรที่สำคัญโดยตรง ( ไม่ใช่ไขระหัส ) ถ้าคุณกำลังทำโครงการแพลตฟอร์มข้ามทราบว่า Enter เป็นที่นิยมใช้ในเครื่องคอมพิวเตอร์และยูนิกซ์ ในขณะที่ผลตอบแทนที่สำคัญใช้แม็ค . ให้แน่ใจว่าโปรแกรมของคุณจะทำงานบนทุกแพลตฟอร์ม โดยตรวจสอบทั้งเพื่อป้อนและกลับ
เพราะว่าระบบปฏิบัติการจัดการคีย์อีกครั้งแล้วถือกุญแจลงมาอาจทำให้โทรศัพท์หลาย keypressed() . อัตราซ้ำกำหนดโดยระบบปฏิบัติการ และอาจถูกกำหนดค่าที่แตกต่างกันบนคอมพิวเตอร์แต่ละเครื่อง
สังเกตว่ามีตรรกะตัวแปรชื่อเดียวกัน เรียกว่า keypressed . ดูหน้าอ้างอิงสำหรับข้อมูลเพิ่มเติม
เมาส์และกิจกรรมแป้นพิมพ์ทำงานเมื่อโปรแกรมมี draw() . draw() ไม่มี ,รหัสคือ วิ่งเพียงครั้งเดียวแล้วหยุดฟังเหตุการณ์
การแปล กรุณารอสักครู่..