name22

Catch "Tab" w/ keyboard-focus on control

Dec 7th, 2012
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GUIConstants.au3>
  2.  
  3. Opt("GUIOnEventMode", 1)
  4.  
  5. Global $hWnd, $cEdit_1, $cEdit_2, $hEdit_1, $hEdit_2, $iFocusCur = -1
  6.  
  7. $hWnd = GUICreate("Test", 200, 100)
  8. $cEdit_1 = GUICtrlCreateEdit("", 5, 5, 190, 40)
  9. $cEdit_2 = GUICtrlCreateEdit("", 5, 50, 190, 40)
  10. GUISetState()
  11.  
  12. $hEdit_1 = ControlGetHandle($hWnd, "", $cEdit_1)
  13. $hEdit_2 = ControlGetHandle($hWnd, "", $cEdit_2)
  14.  
  15. GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
  16.  
  17. While Sleep(20)
  18.     $hFocus = ControlGetHandle($hWnd, "", ControlGetFocus($hWnd))
  19.     Switch $hFocus
  20.         Case $hEdit_1
  21.             $iFocusCur = $cEdit_1
  22.             HotKeySet("{TAB}", "_Tab")
  23.         Case $hEdit_2
  24.             $iFocusCur = $cEdit_2
  25.             HotKeySet("{TAB}", "_Tab")
  26.         Case Else
  27.             $iFocusCur = -1
  28.             HotKeySet("{TAB}")
  29.     EndSwitch
  30. WEnd
  31.  
  32. Func _Exit()
  33.     Exit
  34. EndFunc
  35.  
  36. Func _Tab()
  37.     If $iFocusCur = -1 Then Return
  38.     Switch $iFocusCur
  39.         Case $cEdit_1
  40.             ConsoleWrite("Tab on Edit 1" & @CRLF)
  41.         Case $cEdit_2
  42.             ConsoleWrite("Tab on Edit 2" & @CRLF)
  43.     EndSwitch
  44. EndFunc
RAW Paste Data