I am monitoring Notepad activi开发者_如何学Goties. I want the character that gets deleted when we press backspace
or delete
.
In addition, I don't want to modify the existing clipboard contents.
It may not be the best solution, but you can do almost anything like this with a little creativity and AutoHotKey.
Here's a sample AHK script I wrote. It executes custom code whenever a user presses backspace
or delete
in a notepad window. Pressing Ctrl+Shift+z
will give you a message box with the delete history. It does make use of the clipboard, but it restores it back to the original value.
This was a 5 minute hack, so I'm sure there are issues with it. Use at your own risk :)
#NoEnv
#SingleInstance
SendMode Input
_removalHistory =
_backupClipboard =
#IfWinActive, ahk_classNotepad
{
Backspace::Delete("left")
Delete::Delete("right")
^+z::MsgBox %_removalHistory%
}
Delete(direction) {
global
BackupAndClearClipboard()
length := GetSelectedLength()
if length = 0 SelectOneCharacter(direction)
Copy()
_removalHistory = %_removalHistory%%clipboard%
Send {Delete}
RestoreClipboard()
}
GetSelectedLength() {
local length = 0
Copy()
StringLen, length, clipboard
return length
}
SelectOneCharacter(direction) {
if (direction = "left") {
Send +{Left}
}
else if (direction = "right") {
Send +{Right}
}
}
Copy() {
Send ^c
ClipWait 0.01
}
BackupAndClearClipboard() {
global
_backupClipboard := ClipboardAll
clipboard =
}
RestoreClipboard() {
global
clipboard := _backupClipboard
_backupClipboard = ;free memory
}
The only way I can think of where it might be possible to do something like this is to inject a DLL into notepad which would let you automate it but I'm not sure if it could pick up this.
An article about how to do this can be found at:
http://www.codeproject.com/KB/COM/automatingwindowsapps.aspx
However, I'd think that it might actually be easier to write your own notepad replacement that could do this for you. Possibly you could just download the source for NotePad++ or similar and amend it.
精彩评论