Jump to content

(Archived) Request for calculator within note editor


Recommended Posts

Posted

Made an autohotkey script for it:

Here's the compiled exe - http://dl.dropbox.com/u/771890/ToKeep/i ... ulator.zip

Using double numpad press or double = press it calculates your previous expression

eg (calculated automatically right now):

1+2 = 3 +5 = 8+3 = 11

Here's the source:

#NoEnv
SendMode Input
#SingleInstance , Force
SetBatchLines, 10ms
~NumLock::RapidHotkey("Calculate" ,2,0.2,1)
~=::RapidHotkey("Calculate" ,2,0.2,1)
Calculate:
ClipBoard =
Send ^x
ClipWait 0.25
IfEqual ClipBoard,, { ; No expression is selected
Send +{Home}^c ; Paragraph shouldn't become empty
ClipWait 0.25
IfEqual ClipBoard,,Return
StringGetPos p, ClipBoard, =, R
StringLeft x, ClipBoard, 0 ; get text before last ":"
StringTrimLeft ClipBoard, ClipBoard, p+1
StringReplace, clipboard, clipboard, =, , All
}
Send {End}
FileDelete C:\$temp$.ahk ; Here will be the temp script written
FileAppend #NoTrayIcon`nClipBoard:=%ClipBoard%, C:\$temp$.ahk
RunWait C:\$temp$.ahk ; Run AHK to execute temp script
Send {End}
Send ` = ^v ; Paste the result after the expression
FileDelete C:\$temp$.ahk

Return

RapidHotkey(keystroke, times="", delay=0.1, IsLabel=0)
{
;Suspend, On
Pattern := Morse(delay*1000)
If (StrLen(Pattern) < 2 and Chr(Asc(times)) != "1")
Return
If (times = "" and InStr(keystroke, Chr(4)))
{
Loop, Parse, keystroke,% Chr(4)
If (StrLen(Pattern) = A_Index+1)
continue := A_Index, times := StrLen(Pattern)
}
Else if (RegExMatch(times, "^\d+$") and InStr(keystroke, Chr(4)))
{
Loop, Parse, keystroke,% Chr(4)
If (StrLen(Pattern) = A_Index+times-1)
times := StrLen(Pattern), continue := A_Index
}
Else if InStr(times, Chr(4))
{
Loop, Parse, times,% Chr(4)
If (StrLen(Pattern) = A_LoopField)
continue := A_Index, times := A_LoopField
}
Else if (times = "")
continue := 1, times := 1
Else if (times = StrLen(Pattern))
continue := 1
If !continue
Return
Loop, Parse, keystroke,% Chr(4)
If (continue = A_Index)
keystr := A_LoopField
Loop, Parse, IsLabel,% Chr(4)
If (continue = A_Index)
IsLabel := A_LoopField
hotkey := RegExReplace(A_ThisHotkey, "[\*\~\$\#\+\!\^]")
Loop % times
backspace .= "{Backspace}"
keywait = Ctrl|Alt|Shift|LWin|RWin
Loop, Parse, keywait, |
KeyWait, %A_LoopField%
If ((!IsLabel or (IsLabel and IsLabel(keystr))) and InStr(A_ThisHotkey, "~") and !RegExMatch(A_ThisHotkey
, "\^[^\!\d]|![^\d]|#|Control|Ctrl|LCtrl|RCtrl|Shift|RShift|LShift|RWin|LWin|Escape|BackSpace|F\d\d?|"
. "Insert|Esc|Escape|BS|Delete|Home|End|PgDn|PgUp|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|AppsKey|"
. "PrintScreen|CtrlDown|Pause|Break|Help|Sleep|Browser_Back|Browser_Forward|Browser_Refresh|Browser_Stop|"
. "Browser_Search|Browser_Favorites|Browser_Home|Volume_Mute|Volume_Down|Volume_Up|MButton|RButton|LButton|"
. "Media_Next|Media_Prev|Media_Stop|Media_Play_Pause|Launch_Mail|Launch_Media|Launch_App1|Launch_App2"))
Send % backspace
If (WinExist("AHK_class #32768") and hotkey = "RButton")
WinClose, AHK_class #32768
If !IsLabel
Send % keystr
else if IsLabel(keystr)
Gosub, %keystr%
Return
}
Morse(timeout = 400) { ;by Laszo -> http://www.autohotkey.com/forum/viewtopic.php?t=16951
tout := timeout/1000
key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
Loop {
t := A_TickCount
KeyWait %key%
Pattern .= A_TickCount-t > timeout
KeyWait %key%,DT%tout%
If (ErrorLevel)
Return Pattern
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...