DAY 016: _MOUSEINPUT - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Official Links (https://staging.qb64phoenix.com/forumdisplay.php?fid=16) +--- Forum: Learning Resources and Archives (https://staging.qb64phoenix.com/forumdisplay.php?fid=13) +---- Forum: Keyword of the Day! (https://staging.qb64phoenix.com/forumdisplay.php?fid=49) +---- Thread: DAY 016: _MOUSEINPUT (/showthread.php?tid=1165) |
RE: DAY 016: _MOUSEINPUT - OldMoses - 12-06-2022 (11-22-2022, 02:00 AM)SMcNeill Wrote: @Pete If you're going that complex, use MBS: https://staging.qb64phoenix.com/showthread.php?tid=138 MBS pretty much does everything I need a mouse to do, and more that I haven't quite figured out yet. I haven't done any "hold and release" type stuff. Once I've grabbed a mouse button event, the very first step in processing it is to clear the buffer with: Code: (Select All) SUB Clear_MB (var AS INTEGER) A bit loopy for a solution, but so far, I've had no more click through events. RE: DAY 016: _MOUSEINPUT - Pete - 12-06-2022 (12-06-2022, 01:39 AM)OldMoses Wrote:(11-22-2022, 02:00 AM)SMcNeill Wrote: @Pete If you're going that complex, use MBS: https://staging.qb64phoenix.com/showthread.php?tid=138 Oh I've made mouse routines far more complex than that one. That's why I labeled it as, "mini_mouse". One thing you might want to consider is... Code: (Select All) DO If I run it without _LIMIT in the SUB my CPU jumps from 6% to 52%. With _LIMIT it idles at 4%. I mean this will only happen if your cat decides to sit on your mouse. Yes, I have a cat... and yes, it sits wherever the hell it wants! What you use is what I also use when the apps are not very involved. Much faster to type it out and get things running. Pete RE: DAY 016: _MOUSEINPUT - OldMoses - 12-06-2022 Thanks for the heads up on that. I'm usually just doing click and release stuff, so it's worked well for me. So a change of position makes a big difference...it should probably go last rather than first, depending on the application. Code: (Select All) DO RE: DAY 016: _MOUSEINPUT - Pete - 12-06-2022 LOL! Well, if you are ever faced with a situation where you need to keep track of the time your cat is and is not on your mouse, you can't be stuck in a loop. That's why I made the more complicated routine, CATWATCH! Code: (Select All) DIM mse AS mm ' Let's do a TYPE instead of passing all variables or doing a DIM SHARE. Oh, I also moved the highlighting routine from the first snippet into the mouse button NOT down condition. That way, if someone drags the held down mouse to the "X" the "X" won't be highlighted. It can now only be highlighted when hovering with the left mouse button up. Pete RE: DAY 016: _MOUSEINPUT - NasaCow - 12-10-2022 So.... I read through this and I want to check my conceptual understanding here. Best to setup a mouse reading sub to poll the current state of the mouse. A basic sub should collect our x,y position (assuming that is in pixels in our program when it is active?), and the state of the left button (assuming the right button is as simple?). I get a little fuzzy on checking the prior state of the button to the current state... Is this to check if the button is still being held down and we don't execute as a general rule in such a state? Or did I miss something? Assuming I don't highlight items, I don't need to worry about holding and dragging? In addition, I assume if I want mouse-reading ability, I would need to place a sub call in each of the do/loops I have in my program where I want to use said mouse? And similiar to keyboard input, I would use a select case and check if at this x and y (do I need to track the start x,y and release x,y to ensure I am still in a defined box click area?) with this mouse click and release flag then do this code. Am I getting the logic right or am missing something here. So conceptual it would look like this, if I am understanding the logic right: Code: (Select All) DO Thank you Steve and Pete. I did start in the wiki but this was much more informative. RE: DAY 016: _MOUSEINPUT - Pete - 12-10-2022 >"In addition, I assume if I want mouse-reading ability, I would need to place a sub call in each of the do/loops I have in my program where I want to use said mouse? Yes, and see comments below for options. >" And similiar to keyboard input, I would use a select case and check if at this x and y (do I need to track the start x,y and release x,y to ensure I am still in a defined box click area?) x, y do not need to be "released." If you want to track the previous coordinates, do this.. Code: (Select All) DO So whatever action a click caused, it did so at the x and y coordinates. Those coordinates now become oldx and oldy, so if you move the mouse, the routine knows there was a location change. For sub-routines, you have two choices I'll discuss here for mouse / keyboard setup. 1) Put the whole read mouse and or keyboard routines in one sub-routine. Advantages: easy to access, debug, and if you put a new routine together, just add the conditions to that one sub Disadvantages: If your routine gets big and complicated, your one mouse sub-routine could get hard to manage. I have one like that. My solution, because I do like having just one actually combined muse and keyboard routine, is to flag where the need for action is coming from, and then use a SELECT CASE in the mouse/keyboard routine to route to the proper action conditions. YOu may want to do a string flag, instead of a numeric one, as it is easier to debug: myflag$ = "draw-to-screen" rather than myflag% = 1. 2) Put together a single mouse reading sub-program and after each call make a separate set of conditions after that call, to handle what the mouse routine spits back. Advantages: You can see what to expect everywhere in your program instead of trying to associate what each flag, in the other example, relates to. Disadvantages: You have to go several places in your code to work on your mouse events. ------------------------------------------------------- In your psuedo-code, I would put Code: (Select All) 'INSERT MOUSE READING SUB HERE Together with your mouse actions sub-routine call, if you want to keep it that way. No need to separate them with code in-between. As far as mixing mouse and keyboard, just make conditions, as needed, if anything conflicts where maybe say when a certain key press is made it takes priority over where the mouse is or any mouse action. A simple example would be if I wanted to hold down the "Z" key to block mouse clicks. I'd have to code the mouse routine to bypass mouse click reading until that key is released. Anyway, try some stuff and if you get stuck, just post your code and ask for help in the Help ME! sub-forum. Pete |