Hi everyone! I recently bought the Casio Graph Math+. I've been testing out Python programming and the new getkey() function. I've run into a peculiar behavior and thought I'd ask for your opinion:
While non-blocking, it seems a call getkey() will still take a significant amount of time if no key is being pressed. However, if a key is being pressed, getkey() returns the key code in a negligible amount of time. For a loop that calls getkey(), this can result in a very noticeable difference in performance depending on key up or key down state.
At the end of this post is a simple example script. It loops indefinitely and prints the loop count and currently pressed key code. Try running it with and without a key pressed. Also try without the getkey() call. In my tests, I measured the following performance for 2000 iterations:
No getkey() call: 33 seconds
getkey(), no button pressed: 49 seconds
getkey(), button pressed: 33 seconds
Maybe this is expected behavior, maybe not. I was at least a bit surprised. Would appreciate any input on this.
Code:
While non-blocking, it seems a call getkey() will still take a significant amount of time if no key is being pressed. However, if a key is being pressed, getkey() returns the key code in a negligible amount of time. For a loop that calls getkey(), this can result in a very noticeable difference in performance depending on key up or key down state.
At the end of this post is a simple example script. It loops indefinitely and prints the loop count and currently pressed key code. Try running it with and without a key pressed. Also try without the getkey() call. In my tests, I measured the following performance for 2000 iterations:
No getkey() call: 33 seconds
getkey(), no button pressed: 49 seconds
getkey(), button pressed: 33 seconds
Maybe this is expected behavior, maybe not. I was at least a bit surprised. Would appreciate any input on this.
Code:
from casioplot import *
i = 0
while 1:
clear_screen()
i = i + 1
key = getkey()
draw_string(100,100,str(i))
draw_string(200,100,str(key))
show_screen()