Page 1 of 1

in-line calculator

Posted: 27 Jan 2017, 13:26
by davebrny
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

Re: in-line calculator

Posted: 27 Jan 2017, 13:39
by Helgef
Good idea :thumbup:
I will test this.

Re: in-line calculator

Posted: 27 Jan 2017, 14:19
by guest3456
vnice

Re: in-line calculator

Posted: 27 Jan 2017, 14:56
by SpecialGuest
nice one - very handy :)
This can greatly improve productivity !

Re: in-line calculator

Posted: 28 Jan 2017, 12:00
by davebrny
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...

Re: in-line calculator

Posted: 28 Jan 2017, 23:19
by vasili111
Interesting idea :)

Re: in-line calculator

Posted: 26 May 2017, 11:56
by davebrny
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

Re: in-line calculator

Posted: 15 Jun 2017, 10:05
by brutus_skywalker
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()
}
	

Re: in-line calculator

Posted: 21 Jun 2017, 04:05
by Helgef
@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.

Re: in-line calculator

Posted: 21 Jun 2017, 08:36
by zhotkey
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.

Re: in-line calculator

Posted: 21 Jun 2017, 13:06
by robertcollier4
Nice, thanks... Check out also this one by derRaphael, which may contain some useful code:
https://autohotkey.com/board/topic/5908 ... -brackets/

Re: in-line calculator

Posted: 22 Jun 2017, 04:09
by boiler
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.

Re: in-line calculator

Posted: 10 Oct 2017, 03:22
by davebrny
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:

Re: in-line calculator

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

Re: in-line calculator

Posted: 04 Feb 2022, 13:44
by PJ_in_FL_USA
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

Re: in-line calculator

Posted: 21 Mar 2023, 00:46
by Amunoto
_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.

Re: in-line calculator

Posted: 16 Feb 2024, 12:51
by mbrandonpace
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