Macro to prevent keypresses

Is it possible to set up a macro that is invoked when a keypress occurs (for instance an alphanumeric key types into a document) which then cancels the text being entered?

Alternatively is there any other way I can prevent documents being edited without relying on setting read-only properties through the file system? Or even to prevent the prompt to save a document when it is modified and about to be closed (can I change the modified status back to unmodified before closing for instance)?

This question is probably a follow-on to 286679/libreoffice-for-viewing-only-locked-down-environment

From my pov a duplicate of LibreOffice for Viewing Only - Locked Down Environment just being asked because of dissatisfaction with the answer provided.

PDF-format? Or " What if the file is modified?"

JohnSUN - this works to prevent the prompt upon closing! Thank you!