in-line calculator

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
davebrny
Posts: 85
Joined: 05 Dec 2016, 06:26

in-line calculator

27 Jan 2017, 13:26

an interfaceless calculator that can be used almost anywhere in windows where you can enter text

- activate the calculator by pressing the = key, type an equation and then press the = key to delete the equation and paste the result, or end with the # key to leave the equation text where it is and paste the result after it
- you can also select equation text and use the hotkeys alt + = or alt + # to calculate it
- if youre using a keyboard that doesnt have a number pad then you can use the letter keys p m x d instead of + - * / which makes this easier to type since you dont have to use the shift key

see the github page for more details


latest release: v2.4.2 (10th october 2017)
https://github.com/davebrny/in-line-calculator/releases

Image
Last edited by davebrny on 10 Oct 2017, 03:33, edited 3 times in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: in-line calculator

27 Jan 2017, 13:39

Good idea :thumbup:
I will test this.
guest3456
Posts: 3478
Joined: 09 Oct 2013, 10:31

Re: in-line calculator

27 Jan 2017, 14:19

vnice

SpecialGuest
Posts: 26
Joined: 15 May 2016, 07:49

Re: in-line calculator

27 Jan 2017, 14:56

nice one - very handy :)
This can greatly improve productivity !
User avatar
davebrny
Posts: 85
Joined: 05 Dec 2016, 06:26

Re: in-line calculator

28 Jan 2017, 12:00

Helgef wrote:Good idea :thumbup:
I will test this.
ive think ironed out all the bugs at this stage (on my system anyway) but if you find some more then be sure to give me a roasting here or on github
SpecialGuest wrote:nice one - very handy :)
This can greatly improve productivity !
yes, the less going back and forth between the windows calculator and some other program the better :D
guest3456 wrote:vnice
thanks!
seems like the same sort of idea yea. i made this nearly a year and a half ago now so that was the last time i checked to see if there was anything similar around. i didnt come across that script by Laszlo though so i must look around for that. do a bit of light pillaging on it maybe...
vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: in-line calculator

28 Jan 2017, 23:19

Interesting idea :)
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
User avatar
davebrny
Posts: 85
Joined: 05 Dec 2016, 06:26

Re: in-line calculator

26 May 2017, 11:56

ive changed how this works slightly.
https://github.com/davebrny/in-line-calculator/releases

instead of the calculator becoming active when you first press one of the number keys, you now have to press the grave/backtick key and then type an equation.
there were a few situations where you could be typing something like a date (12-01-2017) and then one of the end keys (= or #) after it which would mean the date would be calculated by accident... so this should cut down the chances of things like that happening
brutus_skywalker
Posts: 175
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: in-line calculator

15 Jun 2017, 10:05

HERE's A FAR SIMPLER ALTERNATIVE: in just 70lines,

valid inputs are: "x=4+12 OUTPUT: 'x=16' " OR "4+12 OUTPUT: '16' "
Just select the expression you want to calculate & press Ctrl+Shift+C,the answer as in the examples will replace selected expression. CHEERS. :dance:

Code: Select all

#SingleInstance, force
#NoTrayIcon

/*
Copy selected input which must be an expression,then execute it as a separate script that pastes the value of the expression inplace of the selected input:
Examples:	;select the string to evaluate as an expression
x=4+12		OUTPUT: 'x=16'
OR
4+12		OUTPUT:	'16'
*/

^+c::	;calculate select text as an expression
GetExecExpression()
Return

GetExecExpression(){
Send ^c
	; MsgBox, DEBUG1 = %clipboard%
if clipboard contains `=	;if expression is sth like x=123+4524, then the value of x is output as 'x'='value'
	{
	Loop, Parse, clipboard, `=	;split the equation
		{
		if (A_Index=1)
			varOutName:=A_LoopField
		else
			expression.=A_LoopField
		}
	execExp=
	(
	%varOutName%:=%expression%
	%varOutName%:=Round(%varOutName%, 3)
	Clipboard:=%varOutName%
	)
	ExecScript(execExp, true)
	clipBuffer:=Clipboard
	Clipboard:= varOutName . "=" . clipBuffer
	; MsgBox, DEBUG2 = %clipboard%
	if clipBuffer is number
		Send ^v	;once expression is calculated & a valid number in the clipboard paste output value
	else
		MsgBox, 0x40010, %A_ScriptName%, Selected Input was not an expression!
	}
else	;if expression is sth like 2(123+123)/4, then the value of the expression is output as 'value'
	{
	execExp=
	(
	x:=%clipboard%
	x:=Round(x, 3)
	Clipboard:=x
	)
	ExecScript(execExp, true)
	clipBuffer:=Clipboard
	; MsgBox, DEBUG3 = %clipboard%
	if clipBuffer is number
		Send ^v	;once expression is calculated & a valid number in the clipboard paste output value
	else
		MsgBox, 0x40010, %A_ScriptName%, Selected Input was not an expression!
	}
}


; ExecScript: Executes the given code as a new AutoHotkey process.
ExecScript(Script, Wait:=true)
{
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
    exec.StdIn.Write(script)
    exec.StdIn.Close()
    if Wait
        return exec.StdOut.ReadAll()
}
	
Outsourcing Clicks & Presses Since 2004.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: in-line calculator

21 Jun 2017, 04:05

@davebrny
I remember I had some problems with this script too, it might be for the same reasons Pinkfloydd describes. I ended up doing something similar to brutus_skywalker, I use it all the time, so thank you very much for the idea.
zhotkey
Posts: 14
Joined: 21 Jun 2017, 08:22

Re: in-line calculator

21 Jun 2017, 08:36

This script nor Brutus script works with either Unix Exceed or Windows version of Emacs. Brutus script doesn't replace the highlighted text but it sometimes copies the answer to the clipboard but not for the windows version of Emacs. Davebrny's script doesn't work at all for Exceed or Emacs.
robertcollier4
Posts: 33
Joined: 09 Apr 2016, 22:14

Re: in-line calculator

21 Jun 2017, 13:06

Nice, thanks... Check out also this one by derRaphael, which may contain some useful code:
https://autohotkey.com/board/topic/5908 ... -brackets/
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: in-line calculator

22 Jun 2017, 04:09

Just so people new to this thread don't get the wrong impression about davebrny's script: I've been using his original script (without the back tick key to initiate) with a US keyboard, and I really like it. It's usage is simple, which is what matters to the user rather than the number of lines in the code (it's nowhere close to being a resource hog). It also has more features and is more flexible than the simpler code.
User avatar
davebrny
Posts: 85
Joined: 05 Dec 2016, 06:26

Re: in-line calculator

10 Oct 2017, 03:22

i have made a few changes to this script:

- the equals key is now the default trigger that starts the calculator instead of the grave/backtick key
- the default key can now be changed to another key such as #, [ or the backtick
- if "trigger_key" is left blank then the calculator will start when any of the number keys are pressed (like in the original version)
- the number pad enter key can be used to send both the trigger key and endkey
- - this works best when the trigger key is left blank as the enter key will still send 'enter' when the calculator is off

https://github.com/davebrny/in-line-calculator/releases v2.4.2

boiler wrote:I've been using his original script (without the back tick key to initiate)
ive gone back to triggering it with the number keys. even after a few months of trying to use the backtick, i still couldnt get rid of the muscle memory that i had built up with the original script :headwall:
_silence_
Posts: 1
Joined: 04 Feb 2022, 07:47

Re: in-line calculator

04 Feb 2022, 07:52

What a nice, handy tool! Unfortunately only the exe works for me, but not the script itself, any idea why?
PJ_in_FL_USA
Posts: 4
Joined: 25 Aug 2014, 15:09
Location: USA

Re: in-line calculator

04 Feb 2022, 13:44

brutus_skywalker wrote:
15 Jun 2017, 10:05
HERE's A FAR SIMPLER ALTERNATIVE: in just 70lines,

valid inputs are: "x=4+12 OUTPUT: 'x=16' " OR "4+12 OUTPUT: '16' "
Just select the expression you want to calculate & press Ctrl+Shift+C,the answer as in the examples will replace selected expression. CHEERS. :dance:

{code removed}
Put this code into a file, compiled it and tried to start the executable, but got stopped by Windows:

"Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item."

Windows 10 Enterprise, limited account.

Older executables built with AHK don't see to have the same problem.

Anyone else see this error or know of a work-around?

Regards,
PJ
Amunoto
Posts: 15
Joined: 01 Dec 2018, 08:31

Re: in-line calculator

21 Mar 2023, 00:46

_silence_ wrote:
04 Feb 2022, 07:52
What a nice, handy tool! Unfortunately only the exe works for me, but not the script itself, any idea why?
Hello

I have exactly the same problem.
With the exe running, =5p5= is replaced by 10; With the AHK running it just remains.

I would love to have the tool's functionality. I tried to find the problem in the code, but I couldn't figure it out. In fact, I did not even find where the „=“ triggers the script.
Davebrny - do you have any idea why user silence and I have this problem?

Kind regards, Hauke

PS 1 230321-210739: UPDATE
In standard INI file, both trigger_key and result_endkey are set to „=“.
When I change the result_endkey to something else, it works as expected.
mbrandonpace
Posts: 3
Joined: 07 Dec 2017, 15:08

Re: in-line calculator

16 Feb 2024, 12:51

Just discovered this script also does "to the power of" calculations (exponentiation). Just use ** (or bb, tt, xx).

Three squared...
=3xx2= --> 9

Four to the power of four...
=4xx4= --> 256

Square root of sixteen...
=16xx0.5= --> 4

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: wilkster and 46 guests