Advertisement
Guest User

Untitled

a guest
Sep 19th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #Requires AutoHotkey v2
  2.  
  3. ; Function to convert Fahrenheit to Celsius
  4. FahrenheitToCelsius(f) {
  5. return (f - 32) * 5 / 9
  6. }
  7.  
  8. ; Hotstring to trigger the conversion
  9. ::fc::
  10. {
  11. ; Create an InputHook object
  12. ih := InputHook("V")
  13. ih.KeyOpt("{Space}{Enter}{Tab}", "E") ; End input on space, enter, or tab
  14. ih.Start()
  15. ih.Wait()
  16. num := ih.Input
  17. ; Extract the numeric part from the input
  18. num := RegExReplace(num, "[^\d.-]")
  19. if (num != "") {
  20. ; Convert the number to Celsius
  21. celsius := FahrenheitToCelsius(num)
  22. ; Delete the original number and "fc"
  23. Send("{Backspace " StrLen(num) + 2 "}")
  24. ; Insert the converted value
  25. Send(Round(celsius, 2) "°C")
  26. }
  27. return
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement