Jump to content
Magikarp7

Enter Hotkey for custom calculator

Recommended Posts

Magikarp7

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 

Share this post


Link to post
Share on other sites
Magikarp7

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

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

×