Jump to content

Enter Hotkey for custom calculator


 Share

Recommended Posts

Hi!

I was trying to make a program with an in-built calculator on a separate tab. The calculator works fine with the operators. But the problem is that when I press the "Enter" key it only functions on the form and when I focus on an internet browser, like GOOGLE, the enter key won't work anymore when I type something in google.

I know that the program is still running. But I set the hotkeys to not work when the GUIform is not active. How do I fix this? Any help will be appreciated! Gonna post some snippets of the code.

Func PressEqual()
 If WinActive($TrackerForm) Then
  MsgBox()
 EndIf
EndFunc 

Link to comment
Share on other sites

Hi!

I was trying to make a program with an in-built calculator on a separate tab. The calculator works fine with the operators. But the problem is that when I press the "Enter" key it only functions on the form and when I focus on an internet browser, like GOOGLE, the enter key won't work anymore when I type something in google.

I know that the program is still running. But I set the hotkeys to not work when the GUIform is not active. How do I fix this? Any help will be appreciated! Gonna post some snippets of the code.The calculator has 2 inputboxes. One inputbox is for the output and the other is a real time tracker of what the user types in.
 

Func PressEqual()
             If WinActive($TrackerForm) Then
                      MsgBox(0,"","Enter working!")
             EndIf
EndFunc 



Switch GUICtrlRead($Tab1)
                        Case 3 ;this is the tab where my calculator is programmed.
                                     If WinActive($TrackerForm) Then
                                                  HotKeySet("{NUMPAD0}", "Press0")
                                                  HotKeySet("{0}", "Press0")
                                                  HotKeySet("{NUMPAD1}", "Press1")
                                                  HotKeySet("{1}", "Press1")
                                                   ;...
                                                   ;etc. etc. etc. for the other hotkeys.
                                                  HotKeySet("{+}", "PressAdd")
                                      EndIf
      
                         Case Else
                                        HotKeySet("{NUMPAD0}")
                                        HotKeySet("{0}")
                                        HotKeySet("{NUMPAD1}")
                                        ;...
                                       ;etc. etc. etc. for the other hotkeys..
                                       HotKeySet("{ENTER}")
EndSwitch


Func PressAdd()
             If WinActive($TrackerForm) Then
                         $getCalcresult = GUICtrlRead($calcresult) ;this inputbox displays the result
                         $getCalcreader = GUICtrlRead($calcreader) ;real time inputbox.

                                    If $getCalcresult = "" And $getCalcreader <> "" Then
                                              $FirstNum = GUICtrlRead($calcreader)
                                              GUICtrlSetData($calcresult, $FirstNum & " + ")
                                    EndIf
  
                                   If $getCalcresult <> "" And $getCalcreader <> "" Then
                                                If StringInStr($getCalcresult, "+") Then
                                                         $FirstNum = $getCalcresult + $getCalcreader
                                                         GUICtrlSetData($calcresult, $FirstNum & " + ")
                                               EndIf
                                   If StringInStr($getCalcresult, "-") Then
                                                        $FirstNum = $getCalcresult - $getCalcreader
                                                        GUICtrlSetData($calcresult, $FirstNum & " + ")
                                  EndIf
                                  If StringInStr($getCalcresult, "*") Then
                                                       $FirstNum = $getCalcresult * $getCalcreader
                                                       GUICtrlSetData($calcresult, $FirstNum & " + ")
                                  EndIf
                                 If StringInStr($getCalcresult, "/") Then
                                                       $FirstNum = $getCalcresult / $getCalcreader
                                                       GUICtrlSetData($calcresult, $FirstNum & " + ")
                                  EndIf
                       EndIf
  GUICtrlSetData($calcreader, "")
 EndIf
EndFunc

 

Edited by Jos
added codebox
Link to comment
Share on other sites

  • Developers

Why did you create a new topic in Examples while you have the question already posted in the other thread?
Merged and moved to support

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...