Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some hex characters get an extra character inserted infront of it and modified #19

Open
edwardlego opened this issue Dec 9, 2022 · 1 comment

Comments

@edwardlego
Copy link

edwardlego commented Dec 9, 2022

some examples of what happens:
79 => 79
80 => C2 80 (this seems to be the lowest affected)
96 => C2 96
A7 => C2 A7
9E => C2 9E
B2 => C2 B2
88 => C2 88
FD => C3 BD
FB => C3 BB
FF => C3 BF
E0 => C3 A0
D0 => C3 90
C0 => C3 80
BF => C2 BF (here seems to be the limit for the character being edited)

I print the characters in the command prompt and they're fine, but when looking in InsideClipboard, I see there's a difference

here's an example of my data i'm having issues with: (left is what I'm trying to achieve, right is when I put the hex values in the clipboard via klembord)
image

edit: so I think this is because the dict I have to put the string of hex characters in doesn't support the characters starting from 80, so it is only a 7 bit string while I need an 8 bit one

@edwardlego
Copy link
Author

solution for my usecase:
i copied from the source the part that actually puts the data in the clipboard and used the encoding "charmap"

content = {'ladderSnippetXML': data}
print(data)
target = 'ladderSnippetXML'
formats = OrderedDict()
for target, data in content.items():
if not isinstance(data, (str, ByteString, type(None))):
raise TypeError('Unsupported data type:\n{}'.format(repr(data)))
elif data:
if target in TARGETS:
if isinstance(data, str):
formats[TARGETS[target]] = data.encode()
else:
formats[TARGETS[target]] = data
print("istarget")
else:
format = windll.user32.RegisterClipboardFormatW(
create_unicode_buffer(target, 1024))
if isinstance(data, str):
formats[format] = data.encode("charmap")
else:
formats[format] = data
if windll.user32.OpenClipboard(None):
windll.user32.EmptyClipboard()
for format, data in formats.items():
handle = windll.kernel32.GlobalAlloc(
GMEM_MOVEABLE | GMEM_ZEROINIT, len(data) + 2)
ptr = windll.kernel32.GlobalLock(handle)
memmove(ptr, data, len(data))
windll.kernel32.GlobalUnlock(ptr)
windll.user32.SetClipboardData(format, handle)
windll.user32.CloseClipboard()
else:
raise RuntimeError('Failed to open clipboard')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant