Announcement

Collapse
No announcement yet.

How do I detect a graphic window click and a graphic keyboard click at the same time?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Edward Collins
    replied
    Thanks. Putting a sleep n statement right inside that very same do loop worked. (Having the sleep statement in a separate thread did not work.)

    I'll also look at the code you both mentioned.

    Leave a comment:


  • Guy Dombrowski
    replied
    Mouse click

    Edward,
    Chris is right, check our postings for the technique.
    You don't have to go into Windows programming to use it properly. Simply add the code you see before PbMain and you will get the use of all 3 mouse buttons plus the scroll wheel.
    As another bonus, you will also trap the Tab Key that the normal code will not see.
    All my new programs are Graphic Console with #CONSOLE OFF and the CPU use is between 1% and 3%

    Leave a comment:


  • Chris Holbrook
    replied
    You have two choices - either use a Windows technique to handle the mouse and keyboard, see Guy Dombrowski's and my recent postings, or use GRAPHIC INKEY$ and look for the mouse event inside a loop which would also contain a SLEEP n statement where n is a small value which does not result in your process gobbling CPU.

    Leave a comment:


  • How do I detect a graphic window click and a graphic keyboard click at the same time?

    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.
Working...
X