Wpis z mikrobloga

Znalazłem w internecie fajny skrypt #autohotkey ale nie znam się mocno na #programowanie
Chciałbym zmienić ten skrypt by działał w polskich warunkach. Przy liczbach niecałkowitych trzeba używać jak rozdzielnika "." (np. 1.05) a chciałbym by było można używać "," czyli żeby uwzględniało liczbę 1,05) . Da się ten skrypt jakoś poprawić ?

-----
/*
[script info]
version = 2.4.2
description = an interface-less calculator for basic math
author = davebrny
source = https://github.com/davebrny/in-line-calculator
*/

;# script settings
#noenv
#singleinstance, force
sendMode input

;# ini settings
iniRead, enablehotstrings, % ascriptDir "\settings.ini", settings, enablehotstrings
iniRead, enable
numberrow, % ascriptDir "\settings.ini", settings, enablenumberrow
iniRead, enablenumberpad, % ascriptDir "\settings.ini", settings, enablenumberpad
iniRead, numpadEnter
endKey, % ascriptDir "\settings.ini", settings, numpadEnterendKey
iniRead, enablehotkeys, % ascriptDir "\settings.ini", settings, enablehotkeys
iniRead, timeout, % a
scriptDir "\settings.ini", settings, timeout
iniRead, triggerkey, % ascriptDir "\settings.ini", settings, triggerkey

;# tray menu stuff
if (a
isCompiled = 1)
menu, tray, add, Reload This Script, reload
menu, tray, icon, % ascriptDir "\in-line calculator.ico"
start
withwindows(1) ; add the option to start the script when windows boots

;# group calculator apps
groupAdd, calculators, Calculator ahk
exe ApplicationFrameHost.exe ; windows 10
groupAdd, calculators, ahkclass CalcFrame ; windows classic
groupAdd, calculators, ahk
exe numbers.exe ; windows 8

;# set hotstrings & hotkeys
hotkey, ifWinNotActive, ahkgroup calculators
if (enable
hotstrings = "yes")
{
if (triggerkey)
{
hotkey, ~%trigger
key%, inlinehotstring, on
delete
n := "2"
}
else ; trigger with any number key or -.(
{
if (enablenumberrow = "yes")
{
loop, 10 ; set 0 to 9 on the number row
hotkey, % "~" . aindex - 1, inlinehotstring, on
hotkey, ~- , inlinehotstring, on
hotkey, ~. , inline
hotstring, on
hotkey, ~( , inlinehotstring, on
}
if (enable
numberpad = "yes")
{
loop, 10 ; set 0 to 9 on the numberpad
hotkey, % "~numpad" . a
index - 1, inlinehotstring, on
hotkey, ~numpadDot, inline
hotstring, on
hotkey, ~numpadSub, inlinehotstring, on
}
delete
n := "1"
}
if (numpadEnterendKey = "yes")
hotkey, ~numpadEnter, numpadEnter
endKey, on
}
if (enablehotkeys = "yes")
{
hotkey, !=, inline
hotkey, on
hotkey, !#, inlinehotkey, on
}
hotkey, ifWinNotActive

;# keys that will end the calculator
end
keys =
(join
{c}{e}{f}{g}{h}{i}{j}{k}{l}{n}{o}{q}{r}{u}{v}{w}{y}{z}{[}{]}{;}{'}{`}{#}{=}{!}{"}
{$}{
%}{^}{&}{}{{}{}}{:}{@}{~}{<}{>}{?}{\}{|}{up}{down}{left}{right}{esc}{enter}
{delete}{backspace}{tab}{LWin}{rWin}{LControl}{rControl}{LAlt}{rAlt}{printScreen}
{home}{end}{insert}{pgUp}{pgDn}{numlock}{scrollLock}{help}{appsKey}{pause}{sleep}
{ctrlBreak}{capsLock}{numpadEnter}{numpadUp}{numpadDown}{numpadLeft}{numpadRight}
{numpadClear}{numpadHome}{numpadEnd}{numpadPgUp}{numpadPgDn}{numpadIns}{numpadDel}
{browser
back}{browserforward}{browserrefresh}{browserstop}{browsersearch}
{browserfavorites}{browserhome}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}
{F12}{F13}{F14}{F15}{F16}{F17}{F18}{F19}{F20}{F21}{F22}{F23}{F24}
)

calculatorstate := "off"

return ; end of auto-execute ---------------------------------------------------

inline
hotstring:
if (calculatorstate = "off")
{
calculator("on")

stringReplace, this
input, athisHotkey, ~ , ,
stringReplace, this
input, thisinput , numpad, ,
stringReplace, this
input, thisinput , enter , ,
stringReplace, this
input, thisinput , dot , .,
stringReplace, this
input, thisinput , sub , -,
stringReplace, this
input, thisinput , %triggerkey%, ,
activewindow := winExist("a")

loop,
{
input, new
input, V %timeout%, %endkeys%
this
input .= newinput ; append
this
endkey := strReplace(errorLevel, "EndKey:", "")
if (thisendkey = "backspace") ; trim and continue with loop/input
stringTrimRight, this
input, thisinput, 1
else break ; if any other end key
}
if (this
endkey = "numpadEnter") and (numpadEnterendKey = "yes")
this
endkey := "="

if (thisendkey != "=") and (thisendkey != "#")
goTo, turncalculatoroff
if (winExist("a") != activewindow)
goTo, turn
calculatoroff

equation := convert
letters(this_input) ; convert letters to math symbols
if equation contains +,-,*,/
goSub, calculateequation

calculator("off")
}
return

inline
hotkey:
clipboard("save")
clipboard("get")
selected := clipboard
equation := convert_letters(trim(selected))
clipboard("restore")

if (equation = "") or if regExMatch(equation, "[^0-9\Q+*-/(),. \E]")
return ; only continue if numbers, +/-*,.() or spaces

if equation not contains +,-,*,/ ; convert spaces to pluses
stringReplace, equation, equation, % aspace, +, all

goSub, calculate
equation
goSub, clearvars
return

calculate
equation:
result := eѵal( strReplace(equation, ",", "") ) ; convert string to expression
if (result != "")
{
if inStr(equation, ",") ; add comma back in to numbers over 1,000
{
stringSplit, split, result, .
result := regExReplace(split1, "(\d)(?=(?:\d{3})+(?:\.|$))", "$1,") "." split2
}
if inStr(result, ".")
result := rTrim( rTrim(result, "0"), ".") ; trim trailing .000

if (athisHotkey = "!=") or (athisHotkey = "!#")
send % "{backspace}" ; delete selected text
else send % "{backspace " strLen(equation) + deleten "}" ; delete hotstring input

clipboard("save")
if (this
endkey = "=") or (athisHotkey = "!=")
clipboard := result
else clipboard := equation " = " result
clipboard("paste")

if (a
thisHotkey = "!=") or (athisHotkey = "!#")
{
clipboard("get")
if (clipboard = selected) ; if clipboard wasnt pasted
{
toolTip, % result
setTimer, msg
timer, 2500
}
}
clipboard("restore")
}
return

calculator(mode) {
global
if (mode = "on")
{
calculatorstate := "on"
menu, tray, icon, % a
scriptDir "\in-line calculator.ico", 2 ; plus icon
}
else if (mode = "off")
{
calculatorstate := "off"
menu, tray, icon, % a
scriptDir "\in-line calculator.ico", 1 ; default icon
goSub, clearvars
}
}

turn
calculatoroff:
calculator("off")
return

convert
letters(string) {
for letters, symbols in {"p":"+", "a":"+", "m":"-", "s":"-"
, "x":"*", "t":"*", "b":"*", "d":"/"}
stringReplace, string, string, % letters, % symbols, all
return string
}

numpadEnterendKey:
if getKeyState("numLock", "T") and (trigger
key != "")
{
send, {backspace}{%triggerkey%}
goSub, inline
hotstring
}
return

clearvars:
this
endkey := ""
thisinput := ""
new
input := ""
equation := ""
selected := ""
return

#ifwinactive, ahk_group calculators

p::send, {+} ; plus
a::send, {+} ; and OR add
m::send, {-} ; minus
s::send, {-} ; subtract
x::send, {*} ; multiply
t::send, {*} ; times
b::send, {*} ; by
d::send, {/} ; divide

=::send, {enter}

#ifwinactive

msgtimer() {
tool
id := winExist("ahkclass tooltipsclass32")
mouseGetPos, , , idunder ; id under cursor
if (id
under != toolid)
{
setTimer, msg
timer, off
toolTip,
}
}

reload:
reload
sleep 1000
msgBox, 4, , The script could not be reloaded and will need to be manually restarted. Would you like Exit?
ifMsgBox, yes, exitApp
return
  • 1
  • Odpowiedz
  • Otrzymuj powiadomienia
    o nowych komentarzach