Author Topic: Mapping the desktop for _SCREENCLICK  (Read 2704 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Mapping the desktop for _SCREENCLICK
« on: December 01, 2018, 04:25:10 pm »
Say I want to open Firefox and run it full screen. If I want to find out where click spots are located, I thought the following would help, but maybe someone has a better approach. I did not include this in the program section, as it is very rudimentary. Basically all it does is ask you to put whatever you want to be displayed and mapped up, press your PrtScr button to d a screen shot, and then it will copy that image and show the mouse coordinates. Move the mouse to what you wanted _SCREENCLICK to activate, and click the left mouse button. The muse cursor will move to position 0, 0 and in about a second, the mouse cursor will appear where it was, only this time that's a _SCREENCLICK but no worries, nothing will happen because this is only a copied image running in this program.

Oh, I had to update to version 1.2 for the _CLIPBOARDIMAGE keyword.

So, any easier ways to do this?

Pete

Code: QB64: [Select]
  1. _SCREENMOVE 0, -25 ' Hides title bar above computer top screen margin.
  2. oldx% = -1: w = 0: v = 0
  3.     x% = _MOUSEX
  4.     y% = _MOUSEY
  5.     mb% = _MOUSEBUTTON(1)
  6.     IF mb% THEN
  7.         mb% = 0
  8.         _MOUSEMOVE 0, 0
  9.         _DELAY 1
  10.         PRINT "Confirmed: Row ="; y%; "   Column ="; x%,
  11.         _SCREENCLICK x%, y%: oldx% = x%: oldy% = y%
  12.         _DELAY 2
  13.     END IF
  14.     IF oldx% <> x% OR oldy% <> y% THEN
  15.         IF dispon% = 0 THEN
  16.             IF _CLIPBOARDIMAGE < -1 THEN
  17.                 _PUTIMAGE (w, v * _FONTHEIGHT), _CLIPBOARDIMAGE
  18.                 dispon% = -1
  19.             ELSE
  20.                 PRINT "Put program to be mapped on screen and do a screen shot..."
  21.                 DO
  22.                     _LIMIT 30
  23.                     IF INKEY$ = CHR$(27) THEN END
  24.                 LOOP UNTIL _CLIPBOARDIMAGE < -1
  25.                 _PUTIMAGE (w, v * _FONTHEIGHT), _CLIPBOARDIMAGE
  26.                 dispon% = -1
  27.             END IF
  28.         END IF
  29.         LOCATE 20, 10: PRINT "Row ="; y%; "   "; "Column ="; x%; "   ";
  30.         oldx% = x%: oldy% = y%
  31.     END IF
  32.  
« Last Edit: December 01, 2018, 05:03:36 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Mapping the desktop for _SCREENCLICK
« Reply #1 on: December 01, 2018, 04:33:59 pm »
This is not an answer to "any easier ways to do this?", but an important warning: Don't call _CLIPBOARDIMAGE like that as every time you do so a new image is created in memory and you'll quickly run out it. Check out the example from the wiki page to see how every time before attempting to fetch a new image from the clipboard I tried to free any previous existing image:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.     CLS
  3.     COLOR _RGB32(177, 177, 177)
  4.     PRINT "Monitoring clipboard..."
  5.     IF img& < -1 THEN _FREEIMAGE img&
  6.     img& = _CLIPBOARDIMAGE
  7.     IF img& < -1 THEN
  8.         PRINT "Image found:"
  9.         COLOR _RGB32(255, 255, 255)
  10.         PRINT "Width :"; _WIDTH(img&)
  11.         PRINT "Height:"; _HEIGHT(img&)
  12.         w = _WIDTH / 2 - _WIDTH(img&) / 2
  13.         IF w < 0 THEN w = 0
  14.         _PUTIMAGE (w, CSRLIN * _FONTHEIGHT), img&
  15.     ELSE
  16.         PRINT "No image found."
  17.     END IF
  18.     _DISPLAY
  19.     _LIMIT 10
  20.  
« Last Edit: December 01, 2018, 04:36:07 pm by FellippeHeitor »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Mapping the desktop for _SCREENCLICK
« Reply #2 on: December 01, 2018, 05:07:27 pm »
I forgot to take out a line when experimenting... I went back and edited out the line: dispon% = 0

So the image isn't freed now, because it is only placed in memory one time. In other words, when dispon%  =  -1, the _CLIPBOARD statement is no longer polled.

So with that modification, is there any need to perform a free image?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Mapping the desktop for _SCREENCLICK
« Reply #3 on: December 01, 2018, 05:32:56 pm »
As said, each time the function is called a new image is created in memory (provided there is one in clipboard). I see it even in a loop condition there, so if you'll poll the clipboard more than once, make sure to always store the handle in a variable and then free it before you poll again.
« Last Edit: December 01, 2018, 06:18:12 pm by FellippeHeitor »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Mapping the desktop for _SCREENCLICK
« Reply #4 on: December 01, 2018, 10:41:14 pm »
Well after the edit, it only gets polled once, but once it is up on the screen, it no longer needs to be hogging memory. I used freeimage in this next example...

I get tired of FireFox session managers going defunct, so I thought some day, I'd make my own. This is a rudimentary program that returns the URLS you choose to save as a session.

WARNING: If you try this code, be aware it will use _SCREENCLICK wherever you left click, so when you make a right click to start the _SCREENCLICK process, it will make a _SCREENCLICK on each of the tabs or whatever it was you left clicked with the mouse.

Code: QB64: [Select]
  1. REDIM tabx(1000) AS INTEGER, taby(1000) AS INTEGER
  2. _SCREENMOVE 100, 100
  3. _CLIPBOARD$ = "" ' Clear any images from clipboard memory.
  4. oldx% = -1: w = 0: v = 0
  5.     IF oldx% <> x% OR oldy% <> y% THEN
  6.         IF dispon% = 0 THEN
  7.             PRINT "Press any key when ready and follow these 3 steps..."
  8.             PRINT
  9.             PRINT "1) Make FireFox full screen."
  10.             PRINT
  11.             PRINT "2) Press PrtScr to make a screen shot."
  12.             PRINT
  13.             PRINT "3) Left click the tabs you want remembered and right click when done."
  14.             DO
  15.                 _LIMIT 30
  16.                 b$ = INKEY$
  17.                 IF b$ = CHR$(27) THEN END
  18.             LOOP UNTIL b$ <> ""
  19.             _SCREENHIDE
  20.             DO
  21.                 _LIMIT 30
  22.                 b$ = INKEY$
  23.                 img& = _CLIPBOARDIMAGE
  24.                 IF INKEY$ = CHR$(27) THEN END
  25.             LOOP UNTIL img& < -1
  26.             GOSUB putimage
  27.             _SCREENSHOW
  28.         END IF
  29.         LOCATE 20, 10: PRINT "Row ="; y%; "   "; "Column ="; x%; "   ";
  30.         oldx% = x%: oldy% = y%
  31.     END IF
  32.     x% = _MOUSEX
  33.     y% = _MOUSEY
  34.     mb% = _MOUSEBUTTON(1)
  35.     rb% = _MOUSEBUTTON(2)
  36.     IF mb% THEN
  37.         mb% = 0
  38.         PRINT "Confirmed: Row ="; y%; "   Column ="; x%,
  39.         num = num + 1
  40.         tabx(num) = x%
  41.         taby(num) = y%
  42.         DO: I = _MOUSEINPUT: LOOP UNTIL _MOUSEBUTTON(1) = 0
  43.     ELSE
  44.         IF rb% THEN
  45.             _SCREENHIDE
  46.             _DELAY .25
  47.             REDIM url$(num)
  48.             FOR I = 1 TO num
  49.                 _SCREENCLICK tabx(I), taby(I)
  50.                 _DELAY .25
  51.                 _SCREENCLICK 700, 80 ' Firefox URL input field.
  52.                 _DELAY .1
  53.                 _SCREENPRINT CHR$(1) ' Select the URL.
  54.                 _DELAY .1
  55.                 _SCREENPRINT CHR$(3) ' Copy the URL.
  56.                 _DELAY .25
  57.                 url$(I) = _CLIPBOARD$
  58.             NEXT
  59.             SCREEN 0
  60.             WIDTH 140, 25
  61.             _SCREENMOVE 100, 100
  62.             _DELAY .1
  63.             _SCREENSHOW
  64.             PRINT "These are your selected URLs...": PRINT
  65.             _DELAY .25
  66.             FOR I = 1 TO num
  67.                 PRINT LTRIM$(STR$(I)); ") "; url$(I)
  68.             NEXT
  69.             PRINT: PRINT "Press any key to exit..."
  70.             DO
  71.                 _LIMIT 30
  72.                 b$ = INKEY$
  73.                 IF b$ <> "" THEN EXIT DO
  74.             LOOP
  75.             EXIT DO
  76.         END IF
  77.     END IF
  78.  
  79. putimage:
  80. _SCREENMOVE 0, -25 ' Hides title bar above computer top screen margin.
  81. _PUTIMAGE (w, v * _FONTHEIGHT), img&
  82. dispon% = -1

Pete
« Last Edit: December 02, 2018, 11:43:57 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/