QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Richard on October 04, 2021, 07:00:06 pm

Title: _SCREENPRINT text$ Question
Post by: Richard on October 04, 2021, 07:00:06 pm
I have referred to the Wiki regarding _SCREENPRINT text$ and wanted to know if there was any way to allow _SCREENPRINT to accept the equivalent of     [Ctrl] + {+}     to enlarge the focused window (when this action is allowed).

As an example, when from QB64 I open NotePad it comes up with the default tiny text size (I do not wish to use say 200% windows scaling for my High DPI Display) and as always with NotePad I need to do    [Ctrl] + {+}    to enlarge the text to a more pleasant size.

Further to this can _SCREENPRINT in general be able to work with any key-combinations eg    [Alt] + [3] 
  and for that matter key scan codes and the such in general?
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 04, 2021, 07:47:08 pm
If you are on a Windows computer, look into using "SENDKEYS"

DECLARE DYNAMIC LIBRARY "user32"
    SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
END DECLARE

CONST KEYEVENTF_KEYUP = &H2
CONST VK_SHIFT = &H10 'Shift key
CONST VK_CTRL = &H11 ' Ctrl key
CONST VK_ALT = &H12 ' Alt key

SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
SENDKEYS &H2B, 0, 0, 0 ' +
SENDKEYS &H2B, 0, KEYEVENTF_KEYUP, 0 ' Release +
SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl


I haven't used ctrl + + before, so I can't attest to the code working, but in theory, it should.

For Alt + 3...

SENDKEYS VK_ALT, 0, 0, 0 ' Alt
SENDKEYS &H33, 0, 0, 0 ' 3
SENDKEYS &H33, 0, KEYEVENTF_KEYUP, 0 ' Release 3
SENDKEYS VK_ALT, 0, KEYEVENTF_KEYUP, 0 ' Release Alt
_DELAY .2

To get the &H hexadecimal codes, just look up the ascii value for the key press, and use an online  decimal to hexadecimal converter.

I hope this helps,

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 04, 2021, 08:45:50 pm
@Pete

Thanks for your quick reply.

As per my program below - it does not seem to work - I am hoping that there is a simple omission/code problem that I have not considered (e.g. "SENDKEYS focus" not being for right window or something?)



Code: QB64: [Select]
  1.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  2.  
  3. CONST KEYEVENTF_KEYUP = &H2
  4. CONST VK_SHIFT = &H10 'Shift key
  5. CONST VK_CTRL = &H11 ' Ctrl key
  6. CONST VK_ALT = &H12 ' Alt key
  7.  
  8.  
  9. NotePad:
  10. 'Code Examples:
  11. 'Example: Printing text into a Windows text editor (Notepad) and copying to the clipboard. May not work on all systems.
  12.  
  13. DEFLNG A-Z
  14. SCREEN _NEWIMAGE(640, 480, 32)
  15. PRINT "OPENing and MAXIMIZING Notepad in 5 seconds..."; : _DELAY 5
  16. SHELL _DONTWAIT "START /MAX NotePad.exe"  'opens Notepad file "untitled.txt"
  17. 'detect notepad open and maximized
  18. 'condition: 80% or more of the screen is white
  19. DO                     'read the desktop screen image for maximized window
  20.     s = _SCREENIMAGE
  21.     _SOURCE s
  22.     z = 0
  23.     FOR y = 0 TO _HEIGHT(s) - 1   'scan for large white area
  24.         FOR x = 0 TO _WIDTH(s) - 1
  25.             c = POINT(x, y)
  26.             IF c = _RGB32(255, 255, 255) THEN z = z + 1
  27.         NEXT
  28.     NEXT
  29.     IF z / (_HEIGHT(s) * _WIDTH(s)) > 0.8 THEN EXIT DO 'when 80% of screen is white
  30.     _FREEIMAGE s   'free desktop image
  31.     _LIMIT 1       'scans 1 loop per second
  32.     PRINT ".";
  33. PRINT "NOTEPAD detected as OPEN and MAXIMIZED"
  34. _SCREENPRINT "HELLO WORLD"
  35. _SCREENPRINT CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) 'backspace 5 characters
  36. _SCREENPRINT "QB64!"
  37.  
  38. gosub Ctrl_Plus:
  39. gosub Ctrl_Plus:
  40. gosub Ctrl_Plus:
  41. gosub Ctrl_Plus:
  42. gosub Ctrl_Plus:
  43.  
  44. _SCREENPRINT CHR$(1) 'CTRL + A select all
  45. _SCREENPRINT CHR$(3) 'CTRL + C copy to clipboard
  46. _CLIPBOARD$ = "QB64 ROCKS!"
  47. _SCREENPRINT CHR$(22) 'CTRL + V paste from clipboard
  48.  
  49.  
  50.  
  51. Ctrl_Plus:
  52. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  53. SENDKEYS &H2B, 0, 0, 0 ' +
  54. SENDKEYS &H2B, 0, KEYEVENTF_KEYUP, 0 ' Release +
  55. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  56.  
  57.  


The main code part came from the IDE Help screen (_SCREENPRINT) example  and apart from your SENDKEYS stuff I just inserted   GOSUB Ctrl_Plus    five times to replicate      [Ctrl] + {+} .


Hope you can spot the error in my ways.
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 04, 2021, 09:11:43 pm
Appears it needs to be a Windows virtual code. Try &HBB


Yep, just tested it. Works on my system...

Code: QB64: [Select]
  1.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  2.  
  3. CONST KEYEVENTF_KEYUP = &H2
  4. CONST VK_SHIFT = &H10 'Shift key
  5. CONST VK_CTRL = &H11 ' Ctrl key
  6. CONST VK_ALT = &H12 ' Alt key
  7.  
  8.  
  9. NotePad:
  10. 'Code Examples:
  11. 'Example: Printing text into a Windows text editor (Notepad) and copying to the clipboard. May not work on all systems.
  12.  
  13. DEFLNG A-Z
  14. SCREEN _NEWIMAGE(640, 480, 32)
  15. PRINT "OPENing and MAXIMIZING Notepad in 5 seconds...";: _DELAY 5
  16. SHELL _DONTWAIT "START /MAX NotePad.exe" 'opens Notepad file "untitled.txt"
  17. 'detect notepad open and maximized
  18. 'condition: 80% or more of the screen is white
  19. DO 'read the desktop screen image for maximized window
  20.     s = _SCREENIMAGE
  21.     _SOURCE s
  22.     z = 0
  23.     FOR y = 0 TO _HEIGHT(s) - 1 'scan for large white area
  24.         FOR x = 0 TO _WIDTH(s) - 1
  25.             c = POINT(x, y)
  26.             IF c = _RGB32(255, 255, 255) THEN z = z + 1
  27.         NEXT
  28.     NEXT
  29.     IF z / (_HEIGHT(s) * _WIDTH(s)) > 0.8 THEN EXIT DO 'when 80% of screen is white
  30.     _FREEIMAGE s 'free desktop image
  31.     _LIMIT 1 'scans 1 loop per second
  32.     PRINT ".";
  33. PRINT "NOTEPAD detected as OPEN and MAXIMIZED"
  34. _SCREENPRINT "HELLO WORLD"
  35. _SCREENPRINT CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) 'backspace 5 characters
  36. _SCREENPRINT "QB64!"
  37.  
  38. GOSUB Ctrl_Plus
  39. GOSUB Ctrl_Plus
  40. GOSUB Ctrl_Plus
  41. GOSUB Ctrl_Plus
  42. GOSUB Ctrl_Plus
  43.  
  44. _SCREENPRINT CHR$(1) 'CTRL + A select all
  45. _SCREENPRINT CHR$(3) 'CTRL + C copy to clipboard
  46. _CLIPBOARD$ = "QB64 ROCKS!"
  47. _SCREENPRINT CHR$(22) 'CTRL + V paste from clipboard
  48.  
  49.  
  50.  
  51. Ctrl_Plus:
  52.  
  53. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  54. SENDKEYS &HBB, 0, 0, 0 ' +
  55. SENDKEYS &HBB, 0, KEYEVENTF_KEYUP, 0 ' Release +
  56. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  57.  

Notepad never loses focus, but if modifying your program ever causes it to do so, just add a _SCREENCLICK 100, 100.

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 04, 2021, 09:35:54 pm
@Pete

Before your modifications to my code appeared on my screen  - I just changed to as follows

SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
SENDKEYS &HBB, 0, 0, 0 ' +
SENDKEYS &HBB, 0, KEYEVENTF_KEYUP, 0 ' Release +
SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl

and having 10 GOSUB CTRL_Plus instead of 5


Of about a dozen trials half worked!!!  Trials #1 and 3 did not 7,8,9 did not - all others worked as expected.

Because only some did not work, I suspect that I may have to play-around with delay/time settings (to make longer).

Just in case - exactly where do I position _screenclick 100,100  (I am hoping that I do not need to adjust delay/time settings to fix up not working cases)

Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 04, 2021, 09:45:33 pm
Put a _DELAY .2 at the end of the SENDKEY gousb routine...

Code: QB64: [Select]
  1.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  2.  
  3. CONST KEYEVENTF_KEYUP = &H2
  4. CONST VK_SHIFT = &H10 'Shift key
  5. CONST VK_CTRL = &H11 ' Ctrl key
  6. CONST VK_ALT = &H12 ' Alt key
  7.  
  8.  
  9. NotePad:
  10. 'Code Examples:
  11. 'Example: Printing text into a Windows text editor (Notepad) and copying to the clipboard. May not work on all systems.
  12.  
  13. DEFLNG A-Z
  14. SCREEN _NEWIMAGE(640, 480, 32)
  15. PRINT "OPENing and MAXIMIZING Notepad in 5 seconds...";: _DELAY 5
  16. SHELL _DONTWAIT "START /MAX NotePad.exe" 'opens Notepad file "untitled.txt"
  17. 'detect notepad open and maximized
  18. 'condition: 80% or more of the screen is white
  19. DO 'read the desktop screen image for maximized window
  20.     s = _SCREENIMAGE
  21.     _SOURCE s
  22.     z = 0
  23.     FOR y = 0 TO _HEIGHT(s) - 1 'scan for large white area
  24.         FOR x = 0 TO _WIDTH(s) - 1
  25.             c = POINT(x, y)
  26.             IF c = _RGB32(255, 255, 255) THEN z = z + 1
  27.         NEXT
  28.     NEXT
  29.     IF z / (_HEIGHT(s) * _WIDTH(s)) > 0.8 THEN EXIT DO 'when 80% of screen is white
  30.     _FREEIMAGE s 'free desktop image
  31.     _LIMIT 1 'scans 1 loop per second
  32.     PRINT ".";
  33. PRINT "NOTEPAD detected as OPEN and MAXIMIZED"
  34. _SCREENPRINT "HELLO WORLD"
  35. _SCREENPRINT CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) 'backspace 5 characters
  36. _SCREENPRINT "QB64!"
  37.  
  38. FOR i = 1 TO 10
  39.     GOSUB Ctrl_Plus
  40.  
  41. _SCREENPRINT CHR$(1) 'CTRL + A select all
  42. _SCREENPRINT CHR$(3) 'CTRL + C copy to clipboard
  43. _CLIPBOARD$ = "QB64 ROCKS!"
  44. _SCREENPRINT CHR$(22) 'CTRL + V paste from clipboard
  45.  
  46.  
  47.  
  48. Ctrl_Plus:
  49.  
  50. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  51. SENDKEYS &HBB, 0, 0, 0 ' +
  52. SENDKEYS &HBB, 0, KEYEVENTF_KEYUP, 0 ' Release +
  53. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  54. _DELAY 0.33
  55.  

As for the _SCREENCLICK, use it only if you place focus back on your QB64 program, directly before the statement that requires Notepad to be back in focus. Use a slight delay after it, too.

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 04, 2021, 10:22:35 pm
@Pete



Success



For trials #1 to #10 the only issue was with #5 (where I accidently held the F5 key down too long - causing many instances of the program to run (which I did not want to happen)).

So apart from multiple instances of the exact same program (which I never want) - everything worked perfectly for me.


I have noticed with the last few monthly updates of 21H1 that timings for keyboard is very "touchy" - in the earlier days, to do a screen capture (windows) I had to simultaneously press [win key] + [Fn] + [PtSc]  and now if I am too slow to release I get this silly snipping tool (I think) save to Clipboard. Previously I never had a problem with the F5 key (in QB64 IDE general) causing multiple instances of the exact same program to launch)


Code: QB64: [Select]
  1.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  2.  
  3. CONST KEYEVENTF_KEYUP = &H2
  4. CONST VK_SHIFT = &H10 'Shift key
  5. CONST VK_CTRL = &H11 ' Ctrl key
  6. CONST VK_ALT = &H12 ' Alt key
  7.  
  8.  
  9. NotePad:
  10. 'Code Examples:
  11. 'Example: Printing text into a Windows text editor (Notepad) and copying to the clipboard. May not work on all systems.
  12.  
  13. DEFLNG A-Z
  14. SCREEN _NEWIMAGE(640, 480, 32)
  15. PRINT "OPENing and MAXIMIZING Notepad in 5 seconds..."; : _DELAY 5
  16.  
  17. _screenclick 100,100                                                                   '*******************
  18. _delay .5                                                                              '*******************
  19.  
  20. SHELL _DONTWAIT "START /MAX NotePad.exe"  'opens Notepad file "untitled.txt"
  21. 'detect notepad open and maximized
  22. 'condition: 80% or more of the screen is white
  23. DO                     'read the desktop screen image for maximized window
  24.     s = _SCREENIMAGE
  25.     _SOURCE s
  26.     z = 0
  27.     FOR y = 0 TO _HEIGHT(s) - 1   'scan for large white area
  28.         FOR x = 0 TO _WIDTH(s) - 1
  29.             c = POINT(x, y)
  30.             IF c = _RGB32(255, 255, 255) THEN z = z + 1
  31.         NEXT
  32.     NEXT
  33.     IF z / (_HEIGHT(s) * _WIDTH(s)) > 0.8 THEN EXIT DO 'when 80% of screen is white
  34.     _FREEIMAGE s   'free desktop image
  35.     _LIMIT 1       'scans 1 loop per second
  36.     PRINT ".";
  37. PRINT "NOTEPAD detected as OPEN and MAXIMIZED"
  38. _SCREENPRINT "HELLO WORLD"
  39. _SCREENPRINT CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) 'backspace 5 characters
  40. _SCREENPRINT "QB64!"
  41.  
  42. for i%=1 to 10                                                                         '*********************
  43.     gosub Ctrl_Plus:                                                                   '*********************
  44. next                                                                                   '*********************
  45.  
  46. _SCREENPRINT CHR$(1) 'CTRL + A select all
  47. _SCREENPRINT CHR$(3) 'CTRL + C copy to clipboard
  48. _CLIPBOARD$ = "QB64 ROCKS!"
  49. _SCREENPRINT CHR$(22) 'CTRL + V paste from clipboard
  50.  
  51.  
  52.  
  53. Ctrl_Plus:
  54. 'SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  55. 'SENDKEYS &H2B, 0, 0, 0 ' +
  56. 'SENDKEYS &H2B, 0, KEYEVENTF_KEYUP, 0 ' Release +
  57. 'SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  58. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  59. SENDKEYS &HBB, 0, 0, 0 ' +                                                             '********************
  60. SENDKEYS &HBB, 0, KEYEVENTF_KEYUP, 0 ' Release +                                       '********************
  61. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  62.  
  63. _delay .2'4                                                                            '********************
  64.  


Many thanks
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 04, 2021, 10:34:52 pm
You're welcome. Yeah, Windows f'updates seldom do us any favors, although after 10+years of missing the obvious, they finally applied a wrap search to Notepad.

BTW - What type of project are you building with these functions? Just curious.

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 04, 2021, 11:12:22 pm
@Pete


I am attempting to develop techniques whereby "EVERYTHING" is redirected (on my windows 10 x64 Pro) - and starting with KEYBOARD (hopefully expand to include mouse/touchpad movements) etc.

So rather than for me repeating essentially similar keystrokes numerous times over - the "grand plan" is to "outsource" the "repetitive stuff" to another QB64 program which via pre-defined simple rules, "churns out" the required output at which point I simply include into my Main Program.

Case in point - currently in my topic on 128bit math - where I do a comparison of _SINGLE _DOUBLE and _FLOAT to determine my so-called QB64 Number Space - I have (in my program) something like

message$ = " 1000 + 1":c!=1000! + 1!: c#=1000# + 1#: c## = 1000## + 1##......

As @SMcNeill detected (rightfully) a typo (another one also I since found) - I am looking at better ways to achieve the exact same result.

So the plan is to (somewhere) type

Message$ = "1000 + 1"

and re-direct activity to somewhere that then recreates the "full line" message$ = .... (5 lines above), which maybe puts it into an $INCLUDE file ...  So you can see the advantage for me to just type Message$ = "1000 + 1". I wanted everything to be explicitly coded (eg c!=1000! c#=1000#   rather than  saying c##=1000## c#=c## c!=c## to make my analysis for the QB64 Number Space more robust). There are many thousands of such message$ lines I want to check out (looking for so-called "transition points") so it would be nice to minimize typo's.

I can see the potential of redirecting from a file/program instead of from keyboard only in a number of my projects.

Of course there may be other techniques (than using re-directs) - this approach looks more "fun" with far ranging implications.

Hope this gives you a bit of an idea of "why?"
Title: Re: _SCREENPRINT text$ Question
Post by: SMcNeill on October 04, 2021, 11:12:31 pm
Another point of interest:

CTRL + A to Z can often be replicated by using CHR$(1) to CHR$(26).

For example, CTRL-G is CHR$(7).

These were the old terminal control codes, and nearly everything out there still carries support for them even today. You might be able to simply do _SCREENPRINT CHR$(3) for a CTRL-C (copy), for example.  Last I checked, it still worked in notepad and Word and such.
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 04, 2021, 11:23:24 pm
@SMcNeill

Thanks - yes re-   Ctrl  A-Z    (chr$(1) - chr$(26)) as is mentioned in the Wiki for _SCREENPRINT.


I have yet to "discover" for myself what I could do with all of them (in _SCREENPRINT). Also of interest (not tried yet) - what about maybe Ctrl via Chr$(27) - chr$(31) of course ran out of letters?

So a few common ones     Ctrl A,  Ctrl C      I have tried (and they work for me in say NotePad).

Title: Re: _SCREENPRINT text$ Question
Post by: SMcNeill on October 04, 2021, 11:43:08 pm
@SMcNeill

Thanks - yes re-   Ctrl  A-Z    (chr$(1) - chr$(26)) as is mentioned in the Wiki for _SCREENPRINT.


I have yet to "discover" for myself what I could do with all of them (in _SCREENPRINT). Also of interest (not tried yet) - what about maybe Ctrl via Chr$(27) - chr$(31) of course ran out of letters?

So a few common ones     Ctrl A,  Ctrl C      I have tried (and they work for me in say NotePad).

27 to 31 were database or file codes:

27 = Escape
28 = File Separator
29 = Group Separator
30 = Record Separator
31 = Unit Separator
127 = Delete (our other special ANSI terminal code)

And those can be manually pressed via combinations like CTRL-A to CTRL-Z, but I don't remember them all off the top of my head.

CTRL + ^ is one.
CTRL + [, and CTRL + ] are two more, I think.
CTRL +? as well...
_ and \  for the others?

But I don't remember the order now, off the top of my head.
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 04, 2021, 11:44:21 pm
@Richard We do so similar stuff. I work with a lot of html projects, and use QB64 routines with templates to create pages, rather than hard code them. It saves a ton of time. The SENDKEY stuff I learned so I could also incorporate other software, such as image software, into my projects. Essentially my QB64 routines can automate all the commonly used key presses to crop, resize and save images. Fun stuff.

Best wishes with your routines!

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: SMcNeill on October 04, 2021, 11:51:09 pm
And CTRL + @ is CHR$(0) for NULL, if you need it.
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 05, 2021, 12:27:44 am
@Pete @SMcNeill Thanks

So I have a "useable" system via @Pete SENDKEYS stuff  and look forward to expanding into mouse/touchpad movements.

Application of mouse stuff includes when ever I have to restart Windows it takes a while for me to reconfigure my "Mission Control" style live desktop "Task View" equivalent - which includes things like Task Manager, Process Monitor, Downloads folder, etc that I need to resize very tiny. I only have one display (3200 x 1800) and I do not Windows scale beyond 100%. It is amazing how little "non-overlapping" room I have left with say half a dozen "essential' apps (e.g. Task Manager) - and usually I cannot do the Ctrl - thing to make tiny. Also I cannot size down beyond certain limits for each app (Windows apps "hoard" a lot of display real estate even when manually sized down (often only need the equivalent of one fairly short text line, or a graph 1cm x 1cm). I am as an on-going project to write QB64 code to "replace" any window apps in regards to this - ending up (work in progress) with a custom bar (at top of screen) 100 pixels high with the "essential" "need to know" info. (which Task Scheduler loads up automatically for me as well as other things).

So any pointers on stuff (eg like SENDKEYS for keyboard) for mouse/touchpad/pointer would be appreciated for future use by me.
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 05, 2021, 02:14:36 am
QB64 has a some very good mouse handling capabilities. I usually like to mix y inkey and mouse routines together, something like this bare bones example.

Code: QB64: [Select]
  1. mydemo% = -1
  2.     _LIMIT 30
  3.     b$ = INKEY$
  4.     IF LEN(b$) THEN
  5.         SELECT CASE LEN(b$)
  6.             CASE 1
  7.                 SELECT CASE b$
  8.                     CASE CHR$(27): EXIT DO
  9.                     CASE ELSE
  10.                         IF mydemo% THEN mydemo% = 1: CALL mroutine(drag, double_click_lt, mydemo%)
  11.                 END SELECT
  12.             CASE 2
  13.                 SELECT CASE RIGHT$(b$, 1)
  14.                     CASE ELSE
  15.                         IF mydemo% THEN mydemo% = 2: CALL mroutine(drag, double_click_lt, mydemo%)
  16.                 END SELECT
  17.         END SELECT
  18.     ELSE
  19.         CALL mroutine(drag, double_click_lt, mydemo%)
  20.     END IF
  21.  
  22. SUB mroutine (drag, double_click_lt, mydemo%)
  23.     STATIC z1, lclick, bactive, oldmx, oldmy
  24.  
  25.     IF mydemo% > 0 THEN GOSUB mydemo: EXIT SUB
  26.  
  27.     IF lclick THEN
  28.         IF TIMER < z1 THEN z1 = z1 - 86400 ' Midnight adjustment.
  29.         IF TIMER - z1 > .33 THEN lclick = 0
  30.     END IF
  31.  
  32.         mw = mw + _MOUSEWHEEL
  33.     WEND
  34.  
  35.     mx = _MOUSEX
  36.     my = _MOUSEY
  37.     lb = _MOUSEBUTTON(1)
  38.     rb = _MOUSEBUTTON(2)
  39.     mb = _MOUSEBUTTON(3)
  40.  
  41.     IF bactive THEN
  42.         SELECT CASE bactive
  43.             CASE -1
  44.                 IF lb = 0 THEN
  45.                     SELECT CASE lclick
  46.                         CASE 0
  47.                             IF mydemo% THEN mydemo% = 3: GOSUB mydemo
  48.                             lclick = lclick + 1
  49.                         CASE ELSE ' Double click. Completed upon 2nd left button release.
  50.                             IF mydemo% THEN mydemo% = 11: GOSUB mydemo
  51.                             double_click_lt = -1
  52.                             lclick = 0
  53.                     END SELECT
  54.                     bactive = 0
  55.                     IF drag THEN drag = 0
  56.                 ELSE
  57.                     IF mx <> oldmx OR my <> oldmy THEN
  58.                         IF mydemo% THEN mydemo% = 12: GOSUB mydemo
  59.                         drag = -1
  60.                     END IF
  61.                 END IF
  62.             CASE -2
  63.                 IF rb = 0 THEN
  64.                     IF mydemo% THEN mydemo% = 4: GOSUB mydemo
  65.                     bactive = 0
  66.                 END IF
  67.             CASE -3
  68.                 IF mb = 0 THEN
  69.                     IF mydemo% THEN mydemo% = 5: GOSUB mydemo
  70.                     bactive = 0
  71.                 END IF
  72.         END SELECT
  73.     ELSE
  74.         IF lb THEN
  75.             IF mydemo% THEN mydemo% = 6: GOSUB mydemo
  76.             bactive = -1
  77.             z1 = TIMER
  78.         ELSEIF rb THEN
  79.             IF mydemo% THEN mydemo% = 7: GOSUB mydemo
  80.             bactive = -2
  81.         ELSEIF mb THEN
  82.             IF mydemo% THEN mydemo% = 8: GOSUB mydemo
  83.             bactive = -3
  84.         ELSEIF mw THEN
  85.             SELECT CASE mw
  86.                 CASE IS > 0
  87.                     IF mydemo% THEN mydemo% = 9: GOSUB mydemo
  88.                 CASE IS < 0
  89.                     IF mydemo% THEN mydemo% = 10: GOSUB mydemo
  90.             END SELECT
  91.         END IF
  92.     END IF
  93.     oldmx = mx: oldmy = my: mw = 0
  94.     EXIT SUB
  95.  
  96.     mydemo:
  97.     LOCATE 1, 1: PRINT "Last User Status:                                    ";
  98.     LOCATE , 19
  99.     SELECT CASE mydemo%
  100.         CASE 1
  101.             PRINT "1-byte keypress = "; b$
  102.         CASE 2
  103.             PRINT "2-byte keypress = "; b$
  104.         CASE 3
  105.             PRINT "Left button released."
  106.         CASE 4
  107.             PRINT "Right button released."
  108.         CASE 5
  109.             PRINT "Middle button released."
  110.         CASE 6
  111.             PRINT "Left button down."
  112.         CASE 7
  113.             PRINT "Right button down."
  114.         CASE 8
  115.             PRINT "Middle button down."
  116.         CASE 9
  117.             PRINT "Wheel scroll down."
  118.         CASE 10
  119.             PRINT "Wheel scroll up."
  120.         CASE 11
  121.             PRINT "Left button double click."
  122.         CASE 12
  123.             PRINT "Drag..."
  124.     END SELECT
  125.     mydemo% = -1
  126.     RETURN

I used a short sound to represent a left button double-click. All other mouse and wheel demos, including drag are printed to the screen. It is important to determine if your mouse routines will take effect upon button down or button release, and modify the code as needed for those specific circumstances.

As far as advice for SENDKEYS, just this. Remember that we can't easily get feedback for the automated key presses, and Windows loves to interrupt our routines with its many background processes, so don't expect short delays to always be sufficient Once an automated key press is missed, because the prior press wasn't processed quickly enough, the routine will fail.

Pete

EDIT: Changed it from a GOSUB to a SUB routine and improved the messaging display. Also, corrected + to - for midnight adjustment, darn aging process. Modified double click to register after the second left button press is released, instead of upon the second left button being pressed. This just makes it easier to display the double click message, without it being over-written with the left button release message. If I work on this more, I may make a user variable to designate any mouse action to act when button is down or act when the depressed button is released.
Title: Re: _SCREENPRINT text$ Question
Post by: luke on October 05, 2021, 02:17:23 am
CTRL + ^ is one.
CTRL + [, and CTRL + ] are two more, I think.
CTRL +? as well...
_ and \  for the others?

But I don't remember the order now, off the top of my head.
No need to remember them, the character and the control character always differ by 64 on the ASCII chart (on old terminals, the Control key would just force a bit to 0).

Well, you have to lookup the characters on the ASCII table but we have one in the IDE.
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 05, 2021, 09:00:17 pm
@Pete

I have been getting some more practice with your SENDKeys stuff (so far so good) - and now trying to expand into MOUSE stuff.

I have hit a problem with "focusing the mouse to an app".

In the program below what I have attempted to do was

- PROGRAM WINDOW  mouse around for 10 seconds
- switch over to NotePad
- for 10 seconds attempt to mouse around in NotePad
- finally let SENDKEYS do its magic

So far my problem is that I cannot get mouse co-ordinates in NotePad




Code: QB64: [Select]
  1. redim shared title$
  2. redim shared hwnd%&
  3. dim shared color_t~&&,color_m~&&
  4.     SUB      SENDKEYS             ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  5.     FUNCTION FindWindowA%&        (BYVAL ClassName AS _OFFSET, WindowName$) 'find process handle by title
  6.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  7.  
  8. CONST KEYEVENTF_KEYUP = &H2
  9. CONST VK_SHIFT =        &H10 'Shift key
  10. CONST VK_CTRL =         &H11 ' Ctrl key
  11. CONST VK_ALT =          &H12 ' Alt key
  12.  
  13. NotePad:
  14. DEFLNG A-Z
  15. SCREEN _NEWIMAGE(640, 480, 32)
  16. _title "PROGRAM WINDOW":color &hffffff00~&&:locate 3,30:PRINT "This is PROGRAM WINDOW..."; : _DELAY 5
  17. color &hff00ff00~&&:locate 10,1:print "MOUSE around PROGRAM WINDOW for 10 seconds"
  18. color_t~&&=&hff00ff00~&&:color_m~&&=&hfffff000~&& :MouseAround
  19.  
  20. _delay 2:_screenclick 100,100: _delay .5
  21. title$=  "START NotePad.exe"                                                                            '*******************
  22. SHELL _DONTWAIT title$ 'opens Notepad file NOT MAXIMIZED
  23.  
  24. focusApp 'Focused on NotePad
  25. color &hffffffff~&&:play "L16N60"
  26. cls:locate 3,30:print "switch mouse focus to NotePad" :timerold = timer
  27. color &hff00ffff~&&:locate 10,1:print "MOUSE around PROGRAM WINDOW for 10 seconds"
  28. color_t~&&=&hff00ffff~&&:color_m~&&=&hffff0000~&& :MouseAround
  29.  
  30. _SCREENPRINT "HELLO WORLD":
  31. SLEEP 2:_SCREENPRINT CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) 'backspace 5 characters
  32. SLEEP 2:for i%=1 to 10:gosub Ctrl_Plus:next ' MAXIMUM NLARGEMENT of NotePad
  33. _SCREENPRINT CHR$(1) 'CTRL + A select all
  34. SLEEP 2:_SCREENPRINT CHR$(3) 'CTRL + C copy to clipboard
  35. _CLIPBOARD$ = "QB64 ROCKS!"''SLEEP 2
  36. _delay 2:_SCREENPRINT CHR$(22) 'CTRL + V paste from clipboard
  37.  
  38. Ctrl_Plus:
  39. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  40. SENDKEYS &HBB, 0, 0, 0 ' +
  41. SENDKEYS &HBB, 0, KEYEVENTF_KEYUP, 0 ' Release +
  42. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  43. _delay .2                                                                            '********************
  44.  
  45. SUB focusapp
  46. hwnd%& = FindWindowA(0, title$ + CHR$(0))
  47. z& = SetForegroundWindow&(hwnd%&)
  48.  
  49. SUB MouseAround
  50. timerold&=timer
  51.         mx=_mousex:my = _mousey:c&=point(mx,my)
  52.         locate 10,1:print space$(79);:locate 10,1:print _mousex;"x";_mousey;"y    ";hex$(c&)
  53.     loop
  54.     color color_t~&&:locate 10,75:print using "###";timerold+10-timer:color color_m~&&
  55. loop until timer > timerold& +10
  56.  
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 05, 2021, 09:29:14 pm
Since you are no longer opening Notepad in full screen, you are having a problem focusing Notepad. The _SCREENCLICK needs to be placed at line 35.

color_t~&&=&hff00ffff~&&:color_m~&&=&hffff0000~&& :MouseAround
 _DELAY 2:_SCREENCLICK 100,100: _DELAY .5
_SCREENPRINT "HELLO WORLD":

Also, 100, 100 is only going to work if you have notepad open in the top left corner. That means you have to open Notepad manually, move it there, and close it.

I'd go with a Windows API focus by title. I believe "Untitled" is the Notepad default title. Provided there is only one copy of Notepad open, that should work. It's been at least two years since I've made a focus routine for Firefox, so I do not recall the code.

As for the mouse in QB64 finding coordinates in notepad, I do not believe that is conventionally possible. Notepad is not a QB64 program. For an unconventional approach, I suppose you could overlay a QB64 window, make it transparent, and measure the  mouse coordinates that way. This is often handy to see where a _SCREENCLICK should be made.

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: SpriggsySpriggs on October 05, 2021, 09:32:09 pm
You can just use the SetFocus() Windows API function to set focus to the Notepad window and then do your typing. Much more dependable than relying on it being in a specific spot or what color it is. Also, you can use GetWindowRect() from Windows API to find the boundaries of the Notepad window. It will give the coordinates of each corner.
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 05, 2021, 09:44:34 pm
Thanks Indy, that's what I was getting at. Ah, here is a little screen mapper I put together a year or two ago...

Code: QB64: [Select]
  1. DEFINT A-Z
  2.  
  3. CONST HWND_TOPMOST%& = -1
  4. CONST SWP_NOSIZE%& = &H1
  5. CONST SWP_NOMOVE%& = &H2
  6. CONST SWP_SHOWWINDOW%& = &H40
  7.  
  8. DIM Hold AS POINTAPI
  9. TYPE POINTAPI
  10.     X_Pos AS LONG
  11.     Y_Pos AS LONG
  12.  
  13.     FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
  14.     FUNCTION GetForegroundWindow& 'find currently focused process handle
  15.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  16.     FUNCTION SetLayeredWindowAttributes& (BYVAL hwnd AS LONG, BYVAL crKey AS LONG, BYVAL bAlpha AS _UNSIGNED _BYTE, BYVAL dwFlags AS LONG)
  17.     FUNCTION GetWindowLong& ALIAS "GetWindowLongA" (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG)
  18.     FUNCTION SetWindowLong& ALIAS "SetWindowLongA" (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG, BYVAL dwNewLong AS LONG)
  19.     FUNCTION SetWindowPos& (BYVAL hWnd AS LONG, BYVAL hWndInsertAfter AS _OFFSET, BYVAL X AS INTEGER, BYVAL Y AS INTEGER, BYVAL cx AS INTEGER, BYVAL cy AS INTEGER, BYVAL uFlags AS _OFFSET)
  20.     FUNCTION GetAsyncKeyState% (BYVAL vkey AS LONG)
  21.     FUNCTION SetCursorPos (BYVAL x AS LONG, BYVAL y AS LONG)
  22.     FUNCTION GetCursorPos (lpPoint AS POINTAPI)
  23.  
  24. _CLIPBOARD$ = "" ' Clear clipboard.
  25.  
  26. ' Needed for acquiring the hWnd of the window
  27. DIM Myhwnd AS LONG ' Get hWnd value
  28. _TITLE "Translucent window test"
  29. Myhwnd = _WINDOWHANDLE
  30. wdth = 300: hght = 400
  31.  
  32. ' Set screen
  33. s& = _NEWIMAGE(wdth, hght, 32)
  34.  
  35. _SCREENMOVE 800, 50
  36. ' Main loop
  37. Level = 175
  38. SetWindowOpacity Myhwnd, Level
  39.  
  40. DIM logger$(100), logger2$(100)
  41.  
  42.     _LIMIT 30
  43.     msg = GetCursorPos(Hold)
  44.     LOCATE 1, 1: PRINT "Col ="; Hold.X_Pos;: LOCATE 1, 11: PRINT "Row ="; Hold.Y_Pos; "   ";
  45.     IF GetAsyncKeyState(1) THEN
  46.         IF flag THEN
  47.             cnt = cnt + 1
  48.             BEEP
  49.             logger$(cnt) = LTRIM$(STR$(Hold.X_Pos))
  50.             logger2$(cnt) = LTRIM$(STR$(Hold.Y_Pos))
  51.         ELSE
  52.             flag = -1
  53.         END IF
  54.     END IF
  55.     IF GetAsyncKeyState(&H1B) THEN
  56.         EXIT DO 'ESC key exits loop and prints logged key presses
  57.     END IF
  58.         IF oldimage& <> 0 THEN
  59.             oldimage& = s&
  60.             wdth = _RESIZEWIDTH: hght = _RESIZEHEIGHT
  61.             IF hght < 100 OR wdth < 150 THEN
  62.                 IF hght <= 100 THEN hght = 100
  63.                 IF wdth <= 150 THEN wdth = 150
  64.                 _RESIZE OFF
  65.                 _DELAY .2
  66.                 s& = _NEWIMAGE(wdth, hght, 32)
  67.                 SCREEN s&
  68.                 _DISPLAYORDER _SOFTWARE , _HARDWARE
  69.                 _FREEIMAGE oldimage&
  70.                 _RESIZE ON
  71.             ELSE
  72.                 s& = _NEWIMAGE(wdth, hght, 32)
  73.                 SCREEN s&
  74.                 _FREEIMAGE oldimage&
  75.             END IF
  76.             LOCATE 4, 1
  77.             PRINT mystring$;
  78.         ELSE
  79.             oldimage& = s&
  80.         END IF
  81.     END IF
  82.  
  83.     b$ = INKEY$
  84.     IF LEN(b$) THEN
  85.         IF b$ = CHR$(27) THEN SYSTEM
  86.         IF LEN(b$) = 2 THEN
  87.             IF b$ = CHR$(0) + CHR$(59) AND Level < 255 THEN Level = Level + 1: SetWindowOpacity Myhwnd, Level
  88.             IF b$ = CHR$(0) + CHR$(60) AND Level > 0 THEN Level = Level - 1: SetWindowOpacity Myhwnd, Level
  89.             yy = CSRLIN: xx = POS(0): LOCATE 1, 1: PRINT "Press F1/F2 to change opacity"; Level;: LOCATE yy, xx
  90.         ELSE
  91.             PRINT b$;
  92.             mystring$ = mystring$ + b$
  93.         END IF
  94.     END IF
  95.     _DISPLAY
  96. FOR i = 0 TO cnt
  97.     PRINT "_SCREENCLICK "; logger$(i); ", "; logger2$(i)
  98.  
  99. '====================================================================\
  100. SUB SetWindowOpacity (hwnd AS LONG, Level)
  101.     DIM Msg AS LONG
  102.     CONST G = -20
  103.     CONST LWA_ALPHA = &H2
  104.     CONST WS_EX_LAYERED = &H80000
  105.     Msg = GetWindowLong(hwnd, G)
  106.     Msg = Msg OR WS_EX_LAYERED
  107.     action = SetWindowLong(hwnd, G, Msg)
  108.     action = SetLayeredWindowAttributes(hwnd, 0, Level, LWA_ALPHA)
  109.  

It makes a translucent window, which you can size over an app, and find the screenclick coordinates by mousing to the point, left clicking, and press esc when you have all the stuff mapped to see a list of the coordinates in the QB64 program window.

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: SpriggsySpriggs on October 05, 2021, 09:45:13 pm
Oops. Yep, can't use SetFocus. Wrong function. It's SetForegroundWindow. Yep.
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 05, 2021, 10:14:24 pm
I just found my FireFox set focus routine...

Code: QB64: [Select]
  1. ct]
  2.  
  3.     DECLARE DYNAMIC LIBRARY "user32"
  4.         FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'handle by title
  5.         FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
  6.         FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  7.         FUNCTION GetForegroundWindow%& 'find currently focused process handle
  8.     END DECLARE
  9.      
  10.     _SCREENMOVE 300, 200
  11.     title$ = "hwnd Finder"
  12.     _TITLE title$
  13.     find$ = "Bing - mozilla firefox" ' Works but you need active window displayed.
  14.     findqb$ = title$
  15.     SHELL _HIDE "firefox.exe bing.com"
  16.     _DELAY 5
  17.     GOSUB focus
  18.     PRINT "Make Firefox window size and press any key to minimize."
  19.     PRINT "It will restore in 5 sec."
  20.     SLEEP
  21.     x& = ShowWindow&(hwnd%&, 2)
  22.     _DELAY 5
  23.     ' 0 closes app. 1 restores app. 2 minimizes app. 3 maximizes app.
  24.     y& = ShowWindow&(hwnd%&, 1)
  25.     _DELAY .1
  26.     GOSUB focus
  27.     PRINT "Press any key to Maximize Firefox."
  28.     SLEEP
  29.     y& = ShowWindow&(hwnd%&, 3)
  30.     _DELAY .1
  31.     GOSUB focus
  32.     PRINT "Press any key to Close Firefox."
  33.     SLEEP
  34.     y& = ShowWindow&(hwnd%&, 0)
  35.     END
  36.      
  37.     focus:
  38.     hwnd%& = FindWindowA(0, findqb$ + CHR$(0))
  39.     _DELAY .1
  40.     FGwin%& = GetForegroundWindow%& 'get current process in focus
  41.     _DELAY .1
  42.     IF FGwin%& <> hwnd%& THEN z& = SetForegroundWindow&(hwnd%&) 'set focus when necessary
  43.     _DELAY .1
  44.     hwnd%& = FindWindowA(0, find$ + CHR$(0))
  45.     _DELAY .1
  46.     RETURN
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 05, 2021, 11:01:28 pm
@Pete

Just tried out simple changes (have not read/studied replies from @Pete @SpriggsySpriggs yet)

Tried the TRANSPARENT window effect ( i.e. without out the screen mode color at end  so have SCREEN NEWIMAGE(640,480).

This defaults to a SCREEN 0 (more correctly a TEXT SCREEN) - that's OK just means that color 0-31 only and co-ords as per character cell positions (not display pixels).


The TRANSPARENT window is 3200 x 1800 pixels (my native display resolution) and I on purpose offset down to _SCREENMOVE 10,110  (NOTHING to go in top 100 pixel scan rows). When NotePad comes into action - SOMETIMES it is on TOP else underneath the BLACK TRANSPARENT window where I can not see it. Manually I preset NotePad to 0,100 so I always know where the extreme Top Left Hand Corner of NotePad is.  In my way of thinking TRANSPARENT here is more of place a blackboard here instead (Transparent I myself think of simultaneously seeing all the layers underneath).

Apart from a "very jerky sluggish" mouse response (like say 1000 times slower) and maybe updates every 3 seconds or so (which would probably be still OK in my program automation (I wont be at the keyboard most of the time) - I notice that on the 50% of times when NotePad is on TOP that it seems that I have to move the mouse outside of the NotePad region (causing NotePad to go on bottom) and then having the "BLACKBOARD" (TRANSPARENT WINDOW) only I can mouse arround (very slowly).

Thanks for the tip on this unconventional approach.

Just wondering - any way (eg by setting alpha values for all 3200x1800 pixels) that I can change the "BLACKBOARD" to "plain cellophane" as the TRANSPARENT window.

So the above appears somewhat "potentially useable" for me - will try to refine further.  Then to "digest" info from your replies above.
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 05, 2021, 11:35:10 pm
@Pete @SpriggsySpriggs

My program at this stage (subject to change by your advice from above)


Code: QB64: [Select]
  1. redim shared title$
  2. redim shared hwnd%&
  3.  
  4.     SUB      SENDKEYS             ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  5.     FUNCTION FindWindowA%&        (BYVAL ClassName AS _OFFSET, WindowName$) 'find process handle by title
  6.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  7.  
  8. CONST KEYEVENTF_KEYUP = &H2
  9. CONST VK_SHIFT =        &H10 'Shift key
  10. CONST VK_CTRL =         &H11 ' Ctrl key
  11. CONST VK_ALT =          &H12 ' Alt key
  12.  
  13. NotePad:
  14. DEFLNG A-Z
  15. SCREEN _NEWIMAGE(640, 480)', 32)by ommiting screen modes --> TRANSPARENT
  16. _screenmove 10,110 ' attempt to make PROGRAM WINDOW transparent
  17. _title "PROGRAM WINDOW":
  18. color 14:locate 3,30:PRINT "This is PROGRAM WINDOW...";
  19. color 10:locate 5,1:print "MOUSE around PROGRAM WINDOW for 10 seconds"
  20. MouseAround
  21. title$=  "START NotePad.exe"                                                                            '*******************
  22. SHELL _DONTWAIT title$ 'opens Notepad file NOT MAXIMIZED
  23.  
  24. focusApp 'Focused on NotePad
  25. play "L16N60":cls
  26. color 31:locate 3,30:print "switch mouse focus to NotePad" :timerold = timer
  27. color 14:locate 5,1:print "MOUSE around PROGRAM WINDOW for 20 seconds"
  28. MouseAround
  29. _delay 2:_screenclick 300,300: _delay .5
  30. _SCREENPRINT "HELLO WORLD":
  31. SLEEP 2:_SCREENPRINT CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) 'backspace 5 characters
  32. SLEEP 2:for i%=1 to 10:gosub Ctrl_Plus:next ' MAXIMUM NLARGEMENT of NotePad
  33. _SCREENPRINT CHR$(1) 'CTRL + A select all
  34. SLEEP 2:_SCREENPRINT CHR$(3) 'CTRL + C copy to clipboard
  35. _CLIPBOARD$ = "QB64 ROCKS!"''SLEEP 2
  36. _delay 2:_SCREENPRINT CHR$(22) 'CTRL + V paste from clipboard
  37.  
  38. Ctrl_Plus:
  39. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  40. SENDKEYS &HBB, 0, 0, 0 ' +
  41. SENDKEYS &HBB, 0, KEYEVENTF_KEYUP, 0 ' Release +
  42. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  43. _delay .2                                                                            '********************
  44.  
  45. SUB focusapp
  46. hwnd%& = FindWindowA(0, title$ + CHR$(0))
  47. z& = SetForegroundWindow&(hwnd%&)
  48.  
  49. SUB MouseAround
  50. timerold&=timer
  51.         mx=_mousex:my = _mousey:locate 5,4:print space$(70);
  52.         locate 5,5:print _mousex;"x";_mousey;"y    "
  53.     loop
  54.     color 26:locate 5,1:print using "###";timerold+20-timer:color 15
  55. loop until timer > (timerold& +20)
  56.  
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 06, 2021, 01:13:14 am
Try this demo to see how focus to an Untitled Notepad is done.

Code: QB64: [Select]
  1.     FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'handle by title
  2.     FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
  3.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  4.     FUNCTION GetForegroundWindow%& 'find currently focused process handle
  5.  
  6. title$ = "myprog"
  7. _TITLE (title$)
  8.  
  9. SHELL _DONTWAIT "notepad"
  10.  
  11.     title$ = "myprog"
  12.  
  13.     PRINT "Any key to focus on Notepad": GOSUB focus
  14.  
  15.     SLEEP
  16.  
  17.     title$ = "Untitled - Notepad"
  18.  
  19.     PRINT "Click here to focus on QB64.": GOSUB focus
  20.  
  21.     DO
  22.         _LIMIT 30
  23.         WHILE _MOUSEINPUT: WEND
  24.         IF _MOUSEBUTTON(1) THEN EXIT DO
  25.     LOOP
  26.  
  27. focus:
  28. hwnd%& = FindWindowA(0, title$ + CHR$(0))
  29. FGwin%& = GetForegroundWindow%& 'get current process in focus
  30. IF FGwin%& <> hwnd%& THEN z& = SetForegroundWindow&(hwnd%&) 'set focus when necessary
  31. hwnd%& = FindWindowA(0, find$ + CHR$(0))
  32.  

Note in the focus sub, I just changed the findqb$ variable from my Firefox routine to titles$, for simplicity. Also, when you use a Windows focus routine, you should lose the _SCREENCLICK statement.

Pete

Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 06, 2021, 02:15:57 am
@Richard Your routine crashed my system, twice. I rewrote it below. It's a s close as I could approximate to what it looked like you tried to achieve.

Code: QB64: [Select]
  1. REDIM SHARED title$
  2. REDIM SHARED hwnd%&
  3.  
  4.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  5.     FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'handle by title
  6.     FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
  7.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  8.     FUNCTION GetForegroundWindow%& 'find currently focused process handle
  9.  
  10. CONST KEYEVENTF_KEYUP = &H2
  11. CONST VK_SHIFT = &H10 'Shift key
  12. CONST VK_CTRL = &H11 ' Ctrl key
  13. CONST VK_ALT = &H12 ' Alt key
  14.  
  15. NotePad:
  16. DEFLNG A-Z
  17. SCREEN _NEWIMAGE(640, 480, 32)
  18. _SCREENMOVE 10, 110
  19. _TITLE "PROGRAM WINDOW"
  20.  
  21. COLOR &HFF00FF00~&&
  22. LOCATE 5, 1: PRINT "MOUSE around PROGRAM WINDOW for 10 seconds"
  23.  
  24. MouseAround
  25.  
  26. SHELL _HIDE _DONTWAIT "start Notepad" 'opens Notepad file NOT MAXIMIZED
  27.  
  28. PLAY "L16N60": CLS
  29. LOCATE 3, 30: PRINT "switch mouse focus to NotePad": timerold = TIMER
  30. LOCATE 5, 1: PRINT "MOUSE around PROGRAM WINDOW for 10 seconds"
  31. MouseAround
  32.  
  33. title$ = "Untitled - Notepad": focusapp 'Focused on NotePad
  34.  
  35. _SCREENPRINT "HELLO WORLD":
  36. SLEEP 2: _SCREENPRINT CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) 'backspace 5 characters
  37. SLEEP 3: _SCREENPRINT "QB64!"
  38. SLEEP 2: FOR i% = 1 TO 10: GOSUB Ctrl_Plus: NEXT ' MAXIMUM NLARGEMENT of NotePad
  39. _SCREENPRINT CHR$(1) 'CTRL + A select all
  40. SLEEP 2: _SCREENPRINT CHR$(3) 'CTRL + C copy to clipboard
  41. _CLIPBOARD$ = "QB64 ROCKS!" ''SLEEP 2
  42. _DELAY 2: _SCREENPRINT CHR$(22) 'CTRL + V paste from clipboard
  43.  
  44. Ctrl_Plus:
  45. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  46. SENDKEYS &HBB, 0, 0, 0 ' +
  47. SENDKEYS &HBB, 0, KEYEVENTF_KEYUP, 0 ' Release +
  48. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  49. _DELAY .2 '********************
  50.  
  51. SUB focusapp
  52.     hwnd%& = FindWindowA(0, title$ + CHR$(0))
  53.     _DELAY .1
  54.     FGwin%& = GetForegroundWindow%& 'get current process in focus
  55.     _DELAY .1
  56.     IF FGwin%& <> hwnd%& THEN z& = SetForegroundWindow&(hwnd%&) 'set focus when necessary
  57.     _DELAY .1
  58.  
  59. SUB MouseAround
  60.     timerold& = TIMER
  61.     LOCATE 5, 1: PRINT SPACE$(_WIDTH);
  62.     DO
  63.         _LIMIT 120
  64.         WHILE _MOUSEINPUT: WEND
  65.         mx = _MOUSEX: my = _MOUSEY
  66.         LOCATE 5, 5: PRINT _MOUSEX; "x"; _MOUSEY; "y    "
  67.         LOCATE 5, 1: PRINT USING "###"; timerold + 10 - TIMER
  68.     LOOP UNTIL TIMER > (timerold& + 10)

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: SMcNeill on October 06, 2021, 04:23:07 am
If you guys use PowerShell, you can use Get-Location or Get-UiaWindow to get the exact coordinates for your notepad.exe on the screen. 

Code: [Select]
$test = Start-Process notepad.exe -PassThru | Get-UiaWindow #| Get-UiaCurrentPattern -PassThru

$test.Current.BoundingRectangle

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-location?view=powershell-7.1
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 06, 2021, 07:20:33 am



   

@Pete  - sorry to have crashed your computer twice! (I did not mean that to happen)


@Pete @SpriggsySpriggs @SMcNeill



Sorry - I think you are on a different "wavelength" from me - this may be because I have not explained myself very well and/or the example provided is not clear and detailed enough.


I think that @Pete saying that "NotePad is not a QB64 program" sums up the situation (and those words may echo in my mind for the next 25 years). I gather that because NotePad is not a program created by QB64, then now it cannot be truely focused on (I hope I am very wrong with this statement). So far, to date, SENDKEYS seems to be able to focus onto NotePad (i.e. via my QB64 program I can get to do some simple things such as Ctrl+ to enlarge the text) - rather than me being at the keyboard performing those same keystrokes.

If I may restate my program requirements (with a very silly example to hopefully clarify better).


Solely by virtue of my QB64 program alone (i.e. once launched I am not present at the keyboard)....



- open up a QB64 Program window (NOTHING ever to occupying the top 100 scan lines of display)

- for 10 seconds display mouse coordinates (if mouse cursor is over the program window - so if a cat played with the mouse during this time, it is reflected in displayed mouse movements)

- switch over to NotePad (idealy NOT MAXIMIZED - however if this cannot work I would allow it to be MAXIMIZED)

- for 10 seconds display mouse co-ordinates (if mouse cursor is over the non-maximized NotePad window) - i.e. now the co-ords displayed are only with regard to NotePad

- do some SENDKEYS magic ( Ctrl + ) to enlarge the NotePad text area - NOTHING ELSE (so therefore no changes to untitled.txt)

- if mouse is truely "focused" to NotePad - my QB64 program should be able to re-locate the mouse cursor to the Top Right Hand Corner of NotePad (which I would have established experimentally the co-ords of same before hand) and CLOSE NotePad (without me being at keyboard).




Assuming the above can be achieved, then eventually other things such as the color at a certain pixel of NotePad, actually write into NotePad the co-ords where the mouse cursor was at the time in NotePad (or better output to a separate file), minimize the NotePad window, etc could be done I hope.



@Pete regarding your demo program (although not doing the mouse thing as outlined above) - there were problems of no response after the first set of switching "focus" from Program window to NotePad Window. Also having _CLIPBOARD$ = "" made programs a bit more robust (in my case not displaying edits of my program onto the Program Window display).


With regards to the un-conventional TRANSPARENT window overlay (which I call a BLACKBOARD) - I discovered that I cannot even manually operate the mouse "click through" the BLACKBOARD to close NotePad (when NotePad is not on top) - so I do not have a potentially useable system as previously stated. So maybe all this TRANSPARENT stuff only relates to QB64 programs only ???



@SMcNeill    I have never used PowerShell before (have used QB64 SHELL cmd stuff tons of time) - could you provide QB64 code example how to use PowerShell please?
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 06, 2021, 11:30:22 am
All this mouseing around crap is about just wanting to close Notepad????!!!!!!!!!!!!!!!!!!

ARHHHHHHHHHH!

WARNING: THIS KILL EVERY INSTANCE OF NOTEPAD OPEN ON YOUR COMPUTER WITHOUT PROMPTING YOU TO SAVE. IF YOU HAVE OTEHR INSTANCES OF UNSAVED NOTEPAD FILES ON YOUR DESKTOP, SAVE THEM AND CLOSE THEM BEFORE RUNNING THIS CODE.

Code: QB64: [Select]
  1. SHELL _HIDE "taskkill /f /im notepad.exe"
  2.  

That kills ALL Notepad opened. It forces them shut, even though writing to it would normally ask you if you wanted it saved.

Also, you can use sendkeys to send Alt+F then x then n. The n is for "Don't Save"

Pete :D

Title: Re: _SCREENPRINT text$ Question
Post by: SpriggsySpriggs on October 06, 2021, 11:33:21 am
Yeah, I did not get that this was just to close Notepad..... Why would one even need to program that? If you are using notepad to begin with then you are most likely at the machine. I'm so confused.
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 06, 2021, 12:00:50 pm
@SpriggsySpriggs  Hi Indy,

He's trying NOT to be at the machine, at all. The _SCREENCLICK method would work, but you would need to know where to tell QB64 to click. I started out that way, before using SENDKEYS. I HAD to make sure  the app opened in the top right corner; that way, all I needed to do is map the top right screen coordinates. I did the mapping with a separate translucent QB64 app I created. I ran that prog over the MS app I wanted to close, placed the QB64 mouse cursor over the "X" on the app, and read the QB64 prog coordinates. I put those _SCREENCLICK, coordinates in my prog to close the app and my QB64 program clicked the "X" closed for me, provided I set the app I wanted closed in the proper location on my desktop.

Anyway, that said, here is a way to do it with SENDKEY, instead of _SCREENCLICK or TASKKILL...

Code: QB64: [Select]
  1. REDIM SHARED title$
  2. REDIM SHARED hwnd%&
  3.  
  4.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  5.     FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'handle by title
  6.     FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
  7.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  8.     FUNCTION GetForegroundWindow%& 'find currently focused process handle
  9.  
  10. CONST KEYEVENTF_KEYUP = &H2
  11. CONST VK_SHIFT = &H10 'Shift key
  12. CONST VK_CTRL = &H11 ' Ctrl key
  13. CONST VK_ALT = &H12 ' Alt key
  14.  
  15. NotePad:
  16. DEFLNG A-Z
  17. SCREEN _NEWIMAGE(640, 480, 32)
  18. _SCREENMOVE 10, 110
  19. _TITLE "PROGRAM WINDOW"
  20.  
  21. COLOR &HFF00FF00~&&
  22. LOCATE 5, 1: PRINT "MOUSE around PROGRAM WINDOW for 10 seconds"
  23.  
  24. MouseAround
  25.  
  26. SHELL _HIDE _DONTWAIT "start Notepad" 'opens Notepad file NOT MAXIMIZED
  27.  
  28. PLAY "L16N60": CLS
  29. LOCATE 3, 30: PRINT "switch mouse focus to NotePad": timerold = TIMER
  30. LOCATE 5, 1: PRINT "MOUSE around PROGRAM WINDOW for 10 seconds"
  31. MouseAround
  32.  
  33. title$ = "Untitled - Notepad": focusapp 'Focused on NotePad
  34.  
  35. _SCREENPRINT "HELLO WORLD":
  36. SLEEP 2: _SCREENPRINT CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) + CHR$(8) 'backspace 5 characters
  37. SLEEP 3: _SCREENPRINT "QB64!"
  38. SLEEP 2: FOR i% = 1 TO 10: GOSUB Ctrl_Plus: NEXT ' MAXIMUM NLARGEMENT of NotePad
  39. _SCREENPRINT CHR$(1) 'CTRL + A select all
  40. SLEEP 2: _SCREENPRINT CHR$(3) 'CTRL + C copy to clipboard
  41. _CLIPBOARD$ = "QB64 ROCKS!" ''SLEEP 2
  42. _DELAY 2: _SCREENPRINT CHR$(22) 'CTRL + V paste from clipboard
  43. '''''''''''SHELL _HIDE "taskkill /f /im notepad.exe"
  44. GOSUB Close_Notepad
  45.  
  46. Ctrl_Plus:
  47. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  48. SENDKEYS &HBB, 0, 0, 0 ' +
  49. SENDKEYS &HBB, 0, KEYEVENTF_KEYUP, 0 ' Release +
  50. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  51. _DELAY .2 '********************
  52.  
  53. Close_Notepad:
  54. SENDKEYS VK_ALT, 0, 0, 0 ' Alt
  55. SENDKEYS &H46, 0, 0, 0 ' F
  56. SENDKEYS &H58, 0, 0, 0 ' x
  57. SENDKEYS &H58, 0, KEYEVENTF_KEYUP, 0 ' Release
  58. SENDKEYS &H46, 0, KEYEVENTF_KEYUP, 0 ' Release
  59. SENDKEYS VK_ALT, 0, KEYEVENTF_KEYUP, 0 ' Release
  60. SENDKEYS &H4E, 0, 0, 0 ' N
  61. SENDKEYS &H4E, 0, KEYEVENTF_KEYUP, 0 ' Release
  62.  
  63. SUB focusapp
  64.     hwnd%& = FindWindowA(0, title$ + CHR$(0))
  65.     _DELAY .1
  66.     FGwin%& = GetForegroundWindow%& 'get current process in focus
  67.     _DELAY .1
  68.     IF FGwin%& <> hwnd%& THEN z& = SetForegroundWindow&(hwnd%&) 'set focus when necessary
  69.     _DELAY .1
  70.  
  71. SUB MouseAround
  72.     timerold& = TIMER
  73.     LOCATE 5, 1: PRINT SPACE$(_WIDTH);
  74.     DO
  75.         _LIMIT 120
  76.         WHILE _MOUSEINPUT: WEND
  77.         mx = _MOUSEX: my = _MOUSEY
  78.         LOCATE 5, 5: PRINT _MOUSEX; "x"; _MOUSEY; "y    "
  79.         LOCATE 5, 1: PRINT USING "###"; timerold + 10 - TIMER
  80.     LOOP UNTIL TIMER > (timerold& + 10)

If left the TASKKILL part in, I just REMMED it out. What's neat about this method is that it leaves other instances of NOTEPAD alone. It only closes the one in focus.

Also, Richard, Indy here has a cool way of using the Windows API to close Notepad: https://www.qb64.org/forum/index.php?topic=4070.msg134228#msg134228

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 06, 2021, 08:00:13 pm
@Pete

Many thanks


I suppose I should not mention N***P** around here any more...


Your Translucent program is what I really needed for the MouseAround routine. I have it now as a standalone QB64 program and will eventually include it in my custom taskbar (top 100 scan lines of display) - the idea being that "forever" I will always see the cursor co-ordinates which supplements the "cross-hair" cursor. Not that it matters, for some reason the opacity did not change when altering with F1/F2. I am running Windows 10 x64 Pro 21H1 build.

Using your Translucent program (for mouse x y co-ords) - I established the CLOSE for N***P** and also  Settings>Update and Security positions for use with _SCREENCLICK. My main program by itself (without me at the keyboard) opened up a file with N***P** (and without doing anything with SENDKEYS) automatically closed it off (via close button region) and then proceeded to Windows Settings>Update and Security automatically requesting for the updates. Of course with the automation I have to ensure the various windows are where they are supposed to be (Windows for me has a habit of re-arranging things every now and then).

Now for some reason (since using your translucent program) - SENDKEYS with the sequence for      Ctrl +
     types in ========== (for 10 Ctrl + requests) with the virtual &HBB values and if I change to having &H2B nothing happens (therefore no change to file and so N***P** is automatically closed).

I will soon try applying _SCREENCLICK to various things (like auto minimizing various "control panel" windows after say every 10 minutes to help "de-clutter" the overloaded display screen, ending processes in Task Manager such as Skype, Cloud, MS Office,... that I never wanted (and can not seem to get rid of), ensuring AutoStartup processes and only enabled for desired ones, etc - all to be done automatically rather than forever onwards doing manually the same steps very often. It is a "bumpy" road for me approaching the automation of mousing actions in this manner - but at least it is "fun".

Many thanks, once again
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 06, 2021, 08:26:44 pm
@Richard Did you try my code I posted above? It Ctrl + + correctly. You may want to post the code you are getting the 10 = signs for. It seems like the ctrl part of SENDKEY is missing. That usually occurs if the release pairing gets messed up.

Glad it's coming along, but seriously, check out the one I posted above. It closes Notepad with a SENDKEY gosub routine labeled as: Close_Notepad

Pete

Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 06, 2021, 08:48:04 pm
@Pete

Not tried yet - will plan to very soon. I think I should take "a bit of a break" from it (say a number of hours) - to help minimize the number of "silly" mistakes (and consequent confusion) on my part.

Yes by all means (using SENDKEY instead of _CLICKSCREEN) what can be done WITHOUT needing to use a mouse, the better.

I will then "tidy up" the program (that gives  ===) and retest and try to correct any of my "mistakes" - in any case I will report back to you (with the complete code) either way.

So in a matter of just a few days, with your greatly appreciated help, "jumped on to the 'gravy train'" (if I may use that term here) which happened to pass my "station" still at "express speed".

My computer background is via DOS (relatively new to Windows, GUI and mice) - I prefer "old-fashioned" key strokes over micky mousing around - and without insulting you (I hope) - most of my work was on MONOCHROME SCREEN 0.
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 06, 2021, 09:07:26 pm
@Richard My alias is SCREEN ZERO HERO, meaning if you really do want to piss me off, we need to be talking graphics... :D I started programming in 1980. A lot of us around here are old timers.

BTW - You are always welcome to post your code. Just let us know where it is failing. Code posts are almost always easier to debug than discussing the problem. Oh, and don't worry about the N***P** thing. The ARHHHHHHHHHHHH!!! comment was just a comedy bit. I really wasn't upset over that, or the two crashes. All part of the process.

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 06, 2021, 09:21:03 pm
@Pete

Does SCREEN 2 graphics qualify to p*** you off?

At the time SCREEN 2 was included in the package (but not a VGA card or something) for the laptop computer. SCREEN 2 graphics was used by me for "preview work" as most of my graphics was really only ported to a HP laser printer to view any graphics work. Although some kind of basic BASIC came with the laptop, essentially from day 1 I worked only with MS PDS 7.1 (on 6 x 3.5" floppies). It was a celebration when the 512 KByte memory was upgraded to 1 Mbyte.
Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 06, 2021, 09:42:56 pm
SCREEN 2? Die *&*(%*%**^*(%^!!!!!!

At some point I checked out SCREEN 7, 9, 12, and 13. My friend Bob, at The QBasic Forum, worked almost exclusively in 12 and 13. He was a graphics designer. For me, it was business apps, so SCREEN 0 worked best for me.

PDS, nice. PDS was QuickBASIC, with just a few more bells and whistles. I bought a copy of QuickBASIC in 1990. Before that, it was TI BASIC in 1980, and Atari BASIC form 1984 to 1990. So a tape recorder was my first "Drive" of sorts. The Atari had a 5 1/4" Floppy drive. With QB, I had a $4,500 state of the art 486 with Windows 3.1. For that price, it should have got 30 miles to a gallon, but it did manage to live for 25 years. Ah, the good old days.

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: Richard on October 07, 2021, 02:54:49 am
@Pete

Just for your info - code that gives     ===...      instead of doing      Ctrl +

Note that most of the code is not actually used (MouseAbout is being performed by another QB64 program running simultaneously using essentially your Translucent program. Minor changes such as not saving co-ordinates should be evident (ticked out) etc.

On my G:\ drive      a.txt  is a one byte file containing the letter "a" only



Of interest is that many more than 10 = are displayed for me (and no enlargement).

Lets see how times my program crashes your computer this time?

Should you not be able to see the problem with the code - I will, if you want, in the next reply, mention some issues with other apps which may or may not be relevant to the problem.





Code: QB64: [Select]
  1. 'Pete's_Translucent_window_test-005.bas
  2. 'injected code from Pete_Ctrl+-008.bas NotePad example
  3. DEFINT A-Z
  4.  
  5. redim shared title$
  6. redim shared hwnd%&
  7. redim shared Level%
  8. z&=z&:hwnd%&=hwnd%&:title$=""
  9.  
  10. CONST HWND_TOPMOST%& = -1
  11. CONST SWP_NOSIZE%& = &H1
  12. CONST SWP_NOMOVE%& = &H2
  13. CONST SWP_SHOWWINDOW%& = &H40
  14.  
  15. reDIM Hold AS POINTAPI
  16. TYPE POINTAPI
  17.     X_Pos AS LONG
  18.     Y_Pos AS LONG
  19.  
  20.     FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
  21.     FUNCTION GetForegroundWindow& 'find currently focused process handle
  22.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  23.     FUNCTION SetLayeredWindowAttributes& (BYVAL hwnd AS LONG, BYVAL crKey AS LONG, BYVAL bAlpha AS _UNSIGNED _BYTE, BYVAL dwFlags AS LONG)
  24.     FUNCTION GetWindowLong& ALIAS "GetWindowLongA" (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG)
  25.     FUNCTION SetWindowLong& ALIAS "SetWindowLongA" (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG, BYVAL dwNewLong AS LONG)
  26.     FUNCTION SetWindowPos& (BYVAL hWnd AS LONG, BYVAL hWndInsertAfter AS _OFFSET, BYVAL X AS INTEGER, BYVAL Y AS INTEGER, BYVAL cx AS INTEGER, BYVAL cy AS INTEGER, BYVAL uFlags AS _OFFSET)
  27.     FUNCTION GetAsyncKeyState% (BYVAL vkey AS LONG)
  28.     FUNCTION SetCursorPos (BYVAL x AS LONG, BYVAL y AS LONG)
  29.     FUNCTION GetCursorPos (lpPoint AS POINTAPI)
  30.     SUB      SENDKEYS             ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  31.     FUNCTION FindWindowA%&        (BYVAL ClassName AS _OFFSET, WindowName$) 'find process handle by title
  32.  
  33. _CLIPBOARD$ = "" ' Clear clipboard.
  34. goto NotePad:
  35.  
  36. ' Needed for acquiring the hWnd of the window
  37. DIM Myhwnd AS LONG ' Get hWnd value
  38. '_TITLE "Translucent window test"
  39. _TITLE "F1/F2 +/- opacity" ' alt 241 does not give CP437 +/-
  40.  
  41. Myhwnd = _WINDOWHANDLE
  42. dth = 355: hght = 20 ' was 300x400
  43. ' Set screen
  44. s& = _NEWIMAGE(wdth, hght, 32)
  45.  
  46.  
  47. _SCREENMOVE 800, 50
  48. ' Main loop
  49. Level = 40' was 175
  50. SetWindowOpacity Myhwnd, Level  'when Level = bAlpha is 0 the window is completely transparent  =255 opaque
  51.  
  52. '************************************************************88
  53. 'gosub MouseAround:
  54.  
  55.  
  56. NotePad:
  57. DEFLNG A-Z
  58. SCREEN _NEWIMAGE(100, 100,32)
  59. title$=  "START NotePad.exe G:\a.txt"                                                                            '*******************
  60. SHELL _DONTWAIT title$ 'opens Notepad file NOT MAXIMIZED
  61.  
  62. _delay 2:_screenclick 300,300: _delay .5
  63. for i%=1 to 10:gosub Ctrl_Plus:next
  64.  
  65. _screenclick 650,100 ' for temporary NotePad
  66.  
  67. _screenclick 700,1150 ' for temporary Windows Updates
  68. play "L1N30"
  69. system  '*************************************************END OF PROGRAM
  70.  
  71.  
  72. FOR i = 0 TO cnt
  73.     PRINT "_SCREENCLICK "; logger$(i); ", "; logger2$(i)
  74.  
  75. '====================================================================\
  76.  
  77. Ctrl_Plus:
  78. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  79.  
  80. 'SENDKEYS &H2B, 0, 0, 0 ' +                         ' &hBB Virtual
  81. 'SENDKEYS &H2B, 0, KEYEVENTF_KEYUP, 0 ' Release +   ' &hBB Virtual
  82.  
  83. SENDKEYS &HbB, 0, 0, 0 ' +                         ' &hBB Virtual
  84. SENDKEYS &HbB, 0, KEYEVENTF_KEYUP, 0 ' Release +   ' &hBB Virtual
  85.  
  86.  
  87. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  88. _delay .2                                                                            '********************
  89.  
  90. MouseAround:
  91. 'DIM logger$(100), logger2$(100)
  92. timerold=timer
  93.     _LIMIT 30
  94.     msg = GetCursorPos(Hold)
  95.     LOCATE 1, 1: PRINT "Col ="; Hold.X_Pos;: LOCATE 1, 11+1: PRINT "Row ="; Hold.Y_Pos; "   ";
  96.     IF GetAsyncKeyState(1) THEN
  97.         IF flag THEN
  98.             cnt = cnt + 1
  99.  
  100.             Play "L63N60"' was BEEP
  101.             '''logger$(cnt) = LTRIM$(STR$(Hold.X_Pos))
  102.             '''logger2$(cnt) = LTRIM$(STR$(Hold.Y_Pos))
  103.         ELSE
  104.             flag = -1
  105.         END IF
  106.     END IF
  107.     IF GetAsyncKeyState(&H1B) THEN
  108.         EXIT DO 'ESC key exits loop and prints logged key presses
  109.     END IF
  110.         IF oldimage& <> 0 THEN
  111.             oldimage& = s&
  112.             wdth = _RESIZEWIDTH: hght = _RESIZEHEIGHT
  113.             IF hght < 100 OR wdth < 150 THEN
  114.                 IF hght <= 100 THEN hght = 100
  115.                 IF wdth <= 150 THEN wdth = 150
  116.                 _RESIZE OFF
  117.                 _DELAY .2
  118.                 s& = _NEWIMAGE(wdth, hght, 32)
  119.                 SCREEN s&
  120.                 _DISPLAYORDER _SOFTWARE , _HARDWARE
  121.                 _FREEIMAGE oldimage&
  122.                 _RESIZE ON
  123.             ELSE
  124.                 s& = _NEWIMAGE(wdth, hght, 32)
  125.                 SCREEN s&
  126.                 _FREEIMAGE oldimage&
  127.             END IF
  128.             LOCATE 4, 1
  129.             PRINT mystring$;
  130.         ELSE
  131.             oldimage& = s&
  132.         END IF
  133.     END IF
  134.  
  135.     b$ = INKEY$
  136.     IF LEN(b$) THEN
  137.         IF b$ = CHR$(27) THEN SYSTEM
  138.         IF LEN(b$) = 2 THEN
  139.             IF b$ = CHR$(0) + CHR$(59) AND Level < 255 THEN Level = Level + 1: SetWindowOpacity Myhwnd, Level
  140.             IF b$ = CHR$(0) + CHR$(60) AND Level > 0 THEN Level = Level - 1: SetWindowOpacity Myhwnd, Level
  141.             yy = CSRLIN: xx = POS(0): LOCATE 1, 1: PRINT "Press F1/F2 to change... opacity"; Level;: LOCATE yy, xx
  142.         ELSE
  143.             PRINT b$;
  144.             mystring$ = mystring$ + b$
  145.         END IF
  146.     END IF
  147.     _DISPLAY
  148.     if timer>(timerold + 10) then return
  149.  
  150.  
  151. SUB SetWindowOpacity (hwnd AS LONG, Level)
  152. DIM Msg AS LONG
  153. CONST G = -20
  154. CONST LWA_ALPHA = &H2' use bAlpha to determine the opacity of the layered window
  155. CONST WS_EX_LAYERED = &H80000
  156. Msg = GetWindowLong(hwnd, G)
  157. Msg = Msg OR WS_EX_LAYERED
  158. action = SetWindowLong(hwnd, G, Msg)
  159. action = SetLayeredWindowAttributes(hwnd, 0, Level, LWA_ALPHA)'(hwnd,colorref crkey,BYTE bAlpha,DWORD dwflags
  160. 'https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setlayeredwindowattributes
  161. 'when bAlpha is 0 , the window is completely transparent
  162. 'when bAlpha is 255, the window is opaque
  163.  
  164.  

Title: Re: _SCREENPRINT text$ Question
Post by: Pete on October 07, 2021, 04:19:02 pm
You forgot to keep the SENDKEY constants. Paste these statements below the new constants you coded...

Code: QB64: [Select]
  1. CONST KEYEVENTF_KEYUP = &H2
  2. CONST VK_SHIFT = &H10 'Shift key
  3. CONST VK_CTRL = &H11 ' Ctrl key
  4. CONST VK_ALT = &H12 ' Alt key

Pete
Title: Re: _SCREENPRINT text$ Question
Post by: Clippy on October 10, 2021, 08:21:32 pm
Nice to see that Pete has STILL survived in Liberal Fires in California and McNeil is still farming Ginseng in Virginia. Thanks for keeping our WIKI up... surprised M$ has not bought us out!

You can delete my post as irrelevant as it is just text on the internet... Love ya guys! 
Title: Re: _SCREENPRINT text$ Question
Post by: FellippeHeitor on October 10, 2021, 08:24:33 pm
It's Clippy! It's Clippy! Welcome back, Ted! Great to see you around.
Title: Re: _SCREENPRINT text$ Question
Post by: FellippeHeitor on October 10, 2021, 08:31:34 pm
LOL @ the edit... and he reported my post to moderation telling mods I'm a stalker... but I'm the moderator.

Now we have proof it's Ted. 😂😂😂
Title: Re: _SCREENPRINT text$ Question
Post by: Clippy on October 10, 2021, 08:35:38 pm
How many freaking posts do I have to make before I don't need to fill in the stupid questions anymore? Sure hope somebody writes a program to do it AI...

Somehow my old PW seemed to work?
Title: Re: _SCREENPRINT text$ Question
Post by: SMcNeill on October 10, 2021, 09:27:10 pm
How many freaking posts do I have to make before I don't need to fill in the stupid questions anymore? Sure hope somebody writes a program to do it AI...

Somehow my old PW seemed to work?

Is your browser in anonymous mode or something?  I've never seen anyone have to fill in questions before posting before. 

Maybe it's just something special they do for paperclip types around here...
Title: Re: _SCREENPRINT text$ Question
Post by: Clippy on October 10, 2021, 10:15:34 pm
3 times apparently as it doesn't need one now.
Title: Re: _SCREENPRINT text$ Question
Post by: Qwerkey on October 11, 2021, 05:09:05 am
It's Clippy! It's Clippy! Welcome back, Ted! Great to see you around.

@Clippy is back & Version 2!

Time for a celebration.  Good to see ya!
Title: Re: _SCREENPRINT text$ Question
Post by: Dav on October 11, 2021, 09:24:14 am
Hi Clippy!  Welcome back.

- Dav
Title: Re: _SCREENPRINT text$ Question
Post by: bplus on October 11, 2021, 12:41:12 pm
He must know Pete has made his one good post for the month and won't be back to... tar-nation.