-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get Character Code.ahk
118 lines (115 loc) · 4.21 KB
/
Get Character Code.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
--@ Author: Cencyte
--@ Date Released: 2∕2∕24
--@ Description: Select a character from a text field, and then have the character's unicode info displayed in a tooltip.
--@ Version: 0.0
--@ License: MIT
--@ Limitations:
• Doesn't work with notepad
• You need to manually set the path to the Powershell script that accesses the API.
• Released "As-Is"
• Windows only
• Path to file has to not be from Google Drive (G:\)
• List certainly not exhaustive
*/
#Requires AutoHotkey v2.0
#SingleInstance Force
#Warn All, Off
FileEncoding "UTF-8"
Original_Clipboard := ""
global prev_Text := ""
global switched := ""
global output := ""
last_Char := ""
outputArray := ""
pwsh_IsRunning := false
tempFile := A_Temp . "\" . A_ScriptName . ".tmp"
MatchesFile := A_Temp . "\" . "Test-Rest-Matches.tmp"
;♠
;Specify the path for the Powershell script in the psScript variable
psScript := "C:\Users\[Your Username]\Documents\...\Test-Rest.ps1"
;
paused := true
TrayTip "ToolTips Active: Text Selection" , A_ScriptName, "Mute"
TraySetIcon("No (Blue).ico", , true)
MyGui := Gui("+Border +Caption +DPIScale +MaximizeBox +OwnDialogs +Resize", "Get Character Code")
iconsize := 128
hIcon := LoadPicture("No (Blue).ico", "Icon GDI+ w" . iconsize . " h" . iconsize, &imgType)
SendMessage(0x0080, 1, hIcon, MyGui)
SetTimer TooltipLoop, 50
return
TooltipLoop() {
global
if (pwsh_IsRunning) {
return
}
local MouseX
local MouseY
local ControlX
local ControlY
local ControlWidth
local ControlHeight
local ID
CoordMode "Mouse", "Screen"
CoordMode "ToolTip", "Screen"
MouseGetPos(&MouseX, &MouseY, &ID, &control)
title := WinGetTitle(ID)
if title != "" and control {
if GetKeyState("LBUTTON") {
ControlGetPos(&ControlX, &ControlY, &ControlWidth, &ControlHeight, control, ID)
PixelX := (MouseX - ControlX) / ControlWidth
PixelY := (MouseY - ControlY) / ControlHeight
if !(switched) {
switched := true
SelectedChar := ""
outputArrayStr := ""
MouseGetPos(&otherX, &otherY)
Original_Clipboard := A_Clipboard
}
delx := Abs(MouseX - otherX)
if (delx >= 4 && delx <= 20) {
SendInput "^c"
CharCode := Format("{:X}", Ord(SubStr(A_Clipboard, 1, 1)))
SelectedChar := SubStr(A_Clipboard, 1, 1)
if (FileExist(psScript)) {
outputArray := ""
if (SelectedChar != SubStr(Original_Clipboard, 1, 1)) && (last_Char != SelectedChar) {
pwsh_IsRunning := true
RunWait A_ComSpec " /c PowerShell.exe -File `"" . psScript . "`" -CharCode " . CharCode . " -SelectedChar " . SelectedChar . " > `"" . tempFile . "`"", , "Hide"
pwsh_IsRunning := false
output := RegExReplace(FileRead(tempFile, "UTF-8"), "�", "") ;https://en.wikipedia.org/wiki/Non-breaking_space
FileDelete tempFile
FileAppend output, tempFile, "UTF-8"
}
} else {
MsgBox "The file does not exist at the specified path:" . psScript
MsgBox "SelectedChar:" . SelectedChar
}
outputArray := StrSplit(output, "`n", , 4)
len := outputArray.Length
if len == 4 {
outputArrayStr := ""
for index, value in outputArray {
if index == len {
outputArrayStr .= value
} else {
outputArrayStr .= value . "`n"
}
}
}
ToolTip outputArrayStr
return
}
}
else if switched && !(GetKeyState("LBUTTON")) {
outputArrayStr := ""
output := ""
outputArray := ""
switched := false
last_Char := SelectedChar
otherX := 0
A_Clipboard := Original_Clipboard
ToolTip
}
}
}