Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey v2
- ; Function to convert Fahrenheit to Celsius
- FahrenheitToCelsius(f) {
- return (f - 32) * 5 / 9
- }
- ; Hotstring to trigger the conversion
- ::fc::
- {
- ; Create an InputHook object
- ih := InputHook("V")
- ih.KeyOpt("{Space}{Enter}{Tab}", "E") ; End input on space, enter, or tab
- ih.Start()
- ih.Wait()
- num := ih.Input
- ; Extract the numeric part from the input
- num := RegExReplace(num, "[^\d.-]")
- if (num != "") {
- ; Convert the number to Celsius
- celsius := FahrenheitToCelsius(num)
- ; Delete the original number and "fc"
- Send("{Backspace " StrLen(num) + 2 "}")
- ; Insert the converted value
- Send(Round(celsius, 2) "°C")
- }
- return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement