Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
(10-23-2022, 08:41 PM)bplus Wrote: (10-23-2022, 08:36 PM)Spriggsy Wrote: Microsoft discourages usage of the clipboard in this manner but if it works for your specific purpose then nice.
Did they give a reason to go along with discouragement? Some people went as far as copying and pasting passwords, credit card data and stuff like that and were hijacked for it, didn't know a malicious program was able to force copy into the clipboard somehow, or block the attempt by the system to clear the clipboard. It must have peaked off enough people going into or out of a web browser then trying to paste text somewhere. Like when I tried one of @Pete's programs to trigger an URL that resided on the clipboard.
In the past a malicious program could put something into the clipboard to disable something in Internet Explorer. Other things could be done that way because a few companies insisted in providing data into or obtaining data from the clipboard, from paying customers. It sounds paranoid, because there's Data Execution Prevention and stuff like that to check certain sensitive areas of RAM periodically. However, it might be a reason why Windows Defender and/or anti-virus slow things down where they don't have to (eg. computer kept totally offline for weeks).
Posts: 3,966
Threads: 176
Joined: Apr 2022
Reputation:
219
10-24-2022, 12:28 PM
(This post was last modified: 10-24-2022, 12:28 PM by bplus.)
Interesting, thanks! Powerful tools are also dangerous.
b = b + ...
Posts: 660
Threads: 142
Joined: Apr 2022
Reputation:
58
10-24-2022, 01:09 PM
(This post was last modified: 10-24-2022, 08:38 PM by James D Jarvis.)
No fancy local hosting in this example but it is a useful example on how to use _clipboard$ to open another window (well it's really another program) to serve as a control panel.
A simple ascii doodle program that will let the user doodle in the window with the mouse.
(EDIT: updated to use colorpick16.exe)
Code: (Select All) 'clipboard communcation sample
'an ascii doodle pad that opens a control panel app in another window
'
Screen _NewImage(60, 30, 0)
_Title "ClipDoodle"
Cls
_Clipboard$ = "ClipDoodleOn" ' "clears" clipboard for use
Shell _DontWait "pickclip.exe" ' Open the pickclip control panel
Shell _DontWait "colorpick16.exe" ' Open the color control panel
_ControlChr Off
AK = 42
Do
_Limit 100
Do While _MouseInput 'mouse status changes only
_Limit 2000
x = _MouseX
y = _MouseY
If _MouseButton(1) Then
_PrintString (x, y), brush$
End If
Loop
kk$ = InKey$
ik$ = _Clipboard$
If Left$(ik$, 2) = "AC" Then AK = Val(Right$(ik$, Len(ik$) - 2))
If Left$(ik$, 2) = "CK" Then
ff$ = " "
n = 2
Do
n = n + 1
A$ = Mid$(ik$, n, 1)
If A$ <> "/" Then ff$ = ff$ + A$
Loop Until A$ = "/"
bb$ = ""
Do
A$ = Mid$(ik$, n, 1)
If A$ <> "/" Then bb$ = bb$ + A$
n = n + 1
Loop Until n > Len(ik$)
FG = Val(ff$): BG = Val(bb$)
Color FG, BG
End If
brush$ = Chr$(AK)
Loop Until kk$ = Chr$(27)
_Clipboard$ = "QUITCOLORPICK16"
Sleep 1
_Clipboard$ = "QUITCLIPPICK"
System
compile this part as pickclip.exe
Code: (Select All) 'pickclip
'complie as pickclip.exe
'sample of a "control panel" feeding output to the clipboard
Screen _NewImage(33, 20, 0)
_ScreenMove 600, 0
_Title "Pick Clip"
_ControlChr Off
AA = 0
'builds ascii grid
For y = 1 To 16
For x = 1 To 16
_PrintString (x * 2, y), Chr$(AA)
AA = AA + 1
Next
Next
Do
_Limit 100
Do While _MouseInput 'mouse status changes only
x = _MouseX
y = _MouseY
If _MouseButton(1) Then
x = Int(x / 2)
AK = (y - 1) * 16 + (x - 1)
_PrintString (1, 18), " "
If AK > -1 And AK < 256 Then pp$ = "Picked ASCII " + Str$(AK) + " : " + Chr$(AK)
_PrintString (1, 18), pp$
_Clipboard$ = "AC" + Str$(AK)
End If
Loop
kk$ = InKey$
If _Clipboard$ = "QUITCLIPPICK" Then kk$ = "QUITALL"
Loop Until kk$ = "QUITALL" Or kk$ = "Q"
_Clipboard$ = "pickclip did quit" 'so QUIT message isn't left in clipboard
System
When both are compiled clipdoodle will open pickclip. Anytime you click on a character to select it that character will get put in the clipboard as "AC"+ascii# to be read by clipdoodle. If you accidentally close pickclip you can reopen it again without impacting the clipdoodle.
When you quit clipdoodle by pressing <esc> it will put a message on the clipboard telling pickclip to quit as well.
Posts: 660
Threads: 142
Joined: Apr 2022
Reputation:
58
added a color picker to the clipdoodle program above.
compile as colorpick16.exe
Code: (Select All) 'colorpick16
'
'a color picker for mode 0 screens.
'
Screen _NewImage(32, 8, 0)
_ScreenMove 600, 400
_Title "colorpick16"
For y = 0 To 1
For x = 0 To 7
fk = y * 8 + x
p$ = "[ ]"
a$ = _Trim$(Str$(fk))
If Len(a$) = 1 Then
Mid$(p$, 3, 1) = a$
Else
Mid$(p$, 2, 2) = a$
End If
Color fk, 0
If fk = 0 Then Color 0, 7
_PrintString ((x + 1) * 4 - 3, y + 1), p$
Next
Next
_PrintString (1, 4), "Foreground"
_PrintString (1, 5), "Background"
For x = 0 To 7
bk = x
p$ = "[ ]"
a$ = _Trim$(Str$(bk))
Mid$(p$, 3, 1) = a$
Color 0, bk
If bk = 0 Then Color 15, 0
_PrintString ((x + 1) * 4 - 3, 7), p$
Next
fk = 15: bk = 0
Do
_Limit 100
Do While _MouseInput 'mouse status changes only
x = _MouseX
y = _MouseY
If _MouseButton(1) Then
If y >= 1 And y <= 2 Then
fk = (y - 1) * 8 + Int(x / 4)
End If
Color fk, 0
If fk = 0 Then Color fk, 8
_PrintString (12, 4), " "
_PrintString (12, 4), Str$(fk)
If y = 7 Then
bk = Int(x / 4)
End If
Color fk, bk
_PrintString (12, 5), " "
_PrintString (12, 5), Str$(bk)
_Clipboard$ = "CK" + _Trim$(Str$(fk)) + "/" + _Trim$(Str$(bk))
End If
Loop
kk$ = InKey$
ccheck$ = _Clipboard$
If ccheck$ = "QUITCOLORPICK16" Then kk$ = "QUITCOLORPICK16"
Loop Until kk$ = Chr$(27) Or kk$ = "QUITCOLORPICK16"
_Clipboard$ = "pickcolor quit"
System
This will enable the user to change foreground and background colors in the clipdoodle sample posted earlier.
|