Not quite on topic but close. I was running a PB program that required numerous repetitions of Ctrl+V to send a string from the Clipboard to Microsoft's CalcPlus and then retrieve the result back into PB via the Clipboard with Ctrl+C. Lacking working knowledge of API and very new to AutoHotKey, I wrote this script for the latter named CalcPlus.ahk
Code:
#ErrorStdOut ; Send error reports to StdOut ClipWait ; Wait for clipboard to contain text SendInput %clipboard% ; Send clipboard contents to CalcPlus Clipboard = ; Clear clipboard Send ^c ; Send CalcPlus contents to clipboard ClipWait ; Wait for clipboard to contain text Exit ; Terminate script
Code:
Function CalcPlus( _ ByVal s As String _ ' String to pass to CalcPlus ) As String ' Output will be the CalcPlus result ' For coding s, see CalcPlus help file topics: ' "Using keyboard equivalents of Calculator Plus buttons" ' "Using key sequences as functions" ' and experiment. Also see the AutoHotKey help file topic: ' "Send / SendRaw / SendInput / SendPlay / SendEvent: Send Keys & Clicks". Static ProcessId As Dword ' Nonzero after first pass Local ClipResult As Long ' Clipboard error if zero Local t As String ' CalcPlust result string If ProcessId=0 Then ' Do first time only ProcessId=Shell("C:\Program Files\Microsoft Calculator Plus\CalcPlus.exe") Sleep 50 ' Must wait at least ~30 msec (on my computer) ' Insert code below. If ProcessId<=32 Then ? "Shell function failed. Cause: "; Cause: GoTo ErrorHandler End If Clipboard Reset, ClipResult: If ClipResult=0 Then GoTo ErrorHandler Clipboard Set Text s, ClipResult: If ClipResult=0 Then GoTo ErrorHandler Shell "C:\Program Files\AutoHotKey\AutoHotKey.exe "+ _ """C:\Program Files\AutoHotKey\CalcPlus.ahk""" Clipboard Get Text t, ClipResult: If ClipResult=0 Then GoTo ErrorHandler Function=UCase$(t) ' Change "e" to "E" Exit Function ErrorHandler: ? "Clipboard error": Close: WaitKey$: End ' Terminate End Function
Edit: ProcessId contains the following documented codes if Shell failed, thanks to an MCM post that lead to:
http://www.oehive.org/node/528.
The following could be put after the Shell function:
Code:
Local Cause As String Select Case ProcessId Case 0: Cause="The operating system is out of memory or resources." Case 2: Cause="The specified file was not found." Case 3: Cause="The specified path was not found." Case 5: Cause="Windows 95 only: The operating system denied access to the specified file." Case 8: Cause="Windows 95 only: There was not enough memory to complete the operation." Case 10: Cause="Wrong Windows version." Case 11: Cause="The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)." Case 12: Cause="Application was designed for a different operating system." Case 13: Cause="Application was designed for MS-DOS 4.0." Case 15: Cause="Attempt to load a real-mode program." Case 16: Cause="Attempt to load a second instance of an application with non-readonly data segments." Case 19: Cause="Attempt to load a compressed application file." Case 20: Cause="Dynamic-link library (DLL) file failure." Case 26: Cause="A sharing violation occurred." Case 27: Cause="The filename association is incomplete or invalid." Case 28: Cause="The DDE transaction could not be completed because the request timed out." Case 29: Cause="The DDE transaction failed." Case 30: Cause="The DDE transaction could not be completed because other DDE transactions were being processed." Case 31: Cause="There is no application associated with the given filename extension." Case 32: Cause="Windows 95 only: The specified dynamic-link library was not found." Case <=32: Cause="Undocumented." End Select
Code:
Button Key Notes CalcPlus is case-insensitive % % Standard view only; x?y%= is x?(x*y/100)= if ? is any op +,-,*,/ (so x/y%=100/y unless x*y=0) ( ( ) ) * * + + {+} in AutoHotKey +/- F9 Alternatively, ilrl; no effect if display=zero; {F9} in AutoHotKey - - Subtraction, sometimes negation; may reset pending op; see +/- . . Alternatively, comma (,) / / 0 to 9 0 to 9 1/x r = ENTER {Enter} in AutoHotKey A to F A to F or a to f; Hex mode [Abs] @ i @ Not a CalcPlus button And & Ave CTRL+A Statistics mode; ^a in AutoHotKey Backspace BACKSPACE {BS} in AutoHotKey Bin F8 {F8} in AutoHotKey Byte F4 {F4} in AutoHotKey C ESC {Esc} in AutoHotKey; :q if cut and pasted CE DEL {Del} in AutoHotKey cos o Inverse is Arccos(); also Cosh() and Arccosh() Dat INS {Ins} in AutoHotKey; \ if cut and pasted Dec F6 {F6} in AutoHotKey Degrees F2 {F2} in AutoHotKey dms m Inverse is degrees <- ddd.mmsss... Dword F2 {F2} in AutoHotKey Exp x :e if cut and pasted F-E v Display toggle: fixed <-> exponential Grads F4 {F4} in AutoHotKey Hex F5 {F5} in AutoHotKey Hyp h Toggles hyperbolic mode Int ; Inverse is Frac() Inv i Toggles inverse mode ln n Log(); Inverse is Exp() log l Log10(); Inverse is Exp10() Lsh < x*2^y; Inverse is Rsh: x/2^y M+ CTRL+P ^p in AutoHotKey; :p if cut and pasted [M-] F9 CTRL+P F9 Not a CalcPlus button MC CTRL+L ^l in AutoHotKey; :c if cut and pasted Mod % x Mod y MR CTRL+R ^r in AutoHotKey; :r if cut and pasted MS CTRL+M ^m in AutoHotKey; :m if cut and pasted n! ! Gam(x+1); doesn't use Simpson; {!} in AutoHotKey Not ~ Oct F7 {F7} in AutoHotKey Or | pi p Inverse is 2*pi Qword F12 {F12} in AutoHotKey Radians F3 {F3} in AutoHotKey s CTRL+D Statistics mode; ^d in AutoHotKey sin s Inverse is Arcsin(); also Sinh() and Arcsinh() sqrt @ Standard view only; [email protected] in scientific view Sta CTRL+S ^s in AutoHotKey; opens statistics box Sum CTRL+T Statistics mode; ^t in AutoHotKey tan t Inverse is Atn(); also Tanh() and Arctanh() Word F3 {F3} in AutoHotKey Xor ^ {^} in AutoHotKey x^2 @ Inverse is Sqr(x) x^3 # {#} in AutoHotKey; Inverse is cube root x^y y Inverse is x^(1/y) ALT+V s !vs in AutoHotKey; put CalcPlus in scientific mode CTRL+V ^v in AutoHotKey; paste CTRL+C ^c in AutoHotKey; copy [X] ALT+F4 !{F4} in AutoHotKey; close CalcPlus In Statistics box: CAD a Delete all values CD c Delete a specific value [click] Down_arrow {Down} in AutoHotKey; select next entry [click] Up_arrow {Up} in AutoHotKey; select prior entry LOAD l Copy from Statistics box to CalcPlus and return to CalcPlus RET r Return to CalcPlus; use {Ins} to send data [scroll] End {End} in AutoHotKey; select last entry [scroll] Home {Home} in AutoHotKey; select first entry [X] ALT+F4 !{F4} in AutoHotKey; close statistics box
Leave a comment: