I'm writing a program (PBCC 5.0) which is working fine but I've noticed while it's running, my CPU usage is at 100%.
DO
GRAPHIC INKEY$ TO a$
GRAPHIC WINDOW CLICK TO graphic_mouse, g_mouse_x, g_mouse_y
LOOP UNTIL a$ <> "" OR graphic_mouse <> 0
' code to process keyboard and mouse input
After reading a bunch of threads in this forum, I've determined it's because I'm using inkey$.
(Note: I have a separate thread where I allow the computer to "breath" by executing a SLEEP statement, but adding or removing this thread does not help the CPU problem.)
Sure enough, when I remove the GRAPHIC INKEY$ statement and replace it with "GRAPHIC WAITKEY$ TO a$" my CPU drops considerably.
DO
GRAPHIC WAITKEY$ TO a$
GRAPHIC WINDOW CLICK TO graphic_mouse, g_mouse_x, g_mouse_y
LOOP UNTIL a$ <> "" OR graphic_mouse <> 0
Yea. Problem solved. Except that now, as you can see, my program doesn't do what I want. While sitting there for waiting for keyboard input now it doesn't detect the mouseclicks.
This should be easy but I can't figure out how to open up a graphic window, and allow the user to be able to click the graphic keyboard or click the graphic mouse, all while keeping the CPU usage down to a reasonable level.
Thanks in advance for any replies.
DO
GRAPHIC INKEY$ TO a$
GRAPHIC WINDOW CLICK TO graphic_mouse, g_mouse_x, g_mouse_y
LOOP UNTIL a$ <> "" OR graphic_mouse <> 0
' code to process keyboard and mouse input
After reading a bunch of threads in this forum, I've determined it's because I'm using inkey$.
(Note: I have a separate thread where I allow the computer to "breath" by executing a SLEEP statement, but adding or removing this thread does not help the CPU problem.)
Sure enough, when I remove the GRAPHIC INKEY$ statement and replace it with "GRAPHIC WAITKEY$ TO a$" my CPU drops considerably.
DO
GRAPHIC WAITKEY$ TO a$
GRAPHIC WINDOW CLICK TO graphic_mouse, g_mouse_x, g_mouse_y
LOOP UNTIL a$ <> "" OR graphic_mouse <> 0
Yea. Problem solved. Except that now, as you can see, my program doesn't do what I want. While sitting there for waiting for keyboard input now it doesn't detect the mouseclicks.
This should be easy but I can't figure out how to open up a graphic window, and allow the user to be able to click the graphic keyboard or click the graphic mouse, all while keeping the CPU usage down to a reasonable level.
Thanks in advance for any replies.
Comment