Jump to content

Need help in scripting !


Recommended Posts

#include <GUIConstants.au3>

; -------------------------------------------------
; Window
; -------------------------------------------------
GUICreate ("test", 180, 130)
GUIsetstate ()

; -------------------------------------------------
; Label
; -------------------------------------------------

GUICtrlCreateLabel("test", 5, 103)

; -------------------------------------------------
; IsPressed
; -------------------------------------------------

Func _IsPressed($hexKey)
Local $aR, $bO

$hexKey = '0x' & $hexKey
$aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
$bO = 1
Else
$bO = 0
EndIf

Return $bO

EndFunc;==>_IsPressed

; -------------------------------------------------
; Hotkey
; -------------------------------------------------
$on = 0
While 1


If(_ispressed("41")) then
$on = 1
endif
if(_ispressed("42")) then
$on = 0
endif
Wend

; eh
If($on = 1) Then
program()
endif


; -------------------------------------------------
; Main script
; -------------------------------------------------
Func program()

if(_ispressed("31")) then
Send("{NUMPAD1}")

elseif(_ispressed("32")) then
Send("{NUMPAD2}")


elseif(_ispressed("33")) then
Send("{NUMPAD3}")


elseif(_ispressed("34")) then
Send("{NUMPAD4}")


elseif(_ispressed("35")) then
Send("{NUMPAD}")


elseif(_ispressed("3")) then
Send("{NUMPAD}")

endif
endfunc

This program mainly On if i press A, Off if i press B.

After i on, whenever i press 1, it will send a command to press another 1 but using the numpad.

Cant seem to get it to work. Anyone can help? thanks.

Link to comment
Share on other sites

I do not like the way you code... but cant you see that the 'eh' section is never executed?

Try

#include <GUIConstants.au3>

; -------------------------------------------------
; Window
; -------------------------------------------------
GUICreate("test", 180, 130)
GUISetState()

; -------------------------------------------------
; Label
; -------------------------------------------------

GUICtrlCreateLabel("test", 5, 103)

; -------------------------------------------------
; IsPressed
; -------------------------------------------------

Func _IsPressed($hexKey)
   Local $aR, $bO
   
   $hexKey = '0x' & $hexKey
   $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
   If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
      $bO = 1
   Else
      $bO = 0
   EndIf
   
   Return $bO
   
EndFunc  ;==>_IsPressed

; -------------------------------------------------
; Hotkey
; -------------------------------------------------
$on = 0
While 1
   Sleep(1)
   
   If (_IsPressed("41")) Then
      $on = 1
   EndIf
   
   if (_IsPressed("42")) Then
      $on = 0
   EndIf
   
   If ($on = 1) Then
      program()
   EndIf
   
WEnd
; -------------------------------------------------
; Main script
; -------------------------------------------------
Func program()
   
   if (_IsPressed("31")) Then
      Send("{NUMPAD1}")
      
   elseif (_IsPressed("32")) Then
      Send("{NUMPAD2}")
      
      
   elseif (_IsPressed("33")) Then
      Send("{NUMPAD3}")
      
      
   elseif (_IsPressed("34")) Then
      Send("{NUMPAD4}")
      
      
   elseif (_IsPressed("35")) Then
      Send("{NUMPAD}")
      
      
   elseif (_IsPressed("03")) Then
      Send("{NUMPAD}")
      
   EndIf
EndFunc  ;==>program
Link to comment
Share on other sites

Sorry i'm trying very hard to keep it neat.

Anyway thanks alot. It works but..

Whenever i press 1, the program presses like five 1s on the numpad. How can i amke it that whenever i press 1, only one 1 from the numpad would come out ?

thanks alot.

Link to comment
Share on other sites

Sorry i'm trying very hard to keep it neat.

Anyway thanks alot. It works but..

Whenever i press 1, the program presses like five 1s on the numpad. How can i amke it that whenever i press 1, only one 1 from the numpad would come out ?

thanks alot.

<{POST_SNAPBACK}>

Modified your script to use HotKeySet() instead of _IsPressed()

This seems to fix your problem.

However A and B cannot be set as hotkeys :) So i had to use F1 and F2 instead.

#include <GUIConstants.au3>

; -------------------------------------------------
; Window
; -------------------------------------------------
GUICreate("test", 180, 130)
GUISetState()

; -------------------------------------------------
; Label
; -------------------------------------------------

GUICtrlCreateLabel("test", 5, 103)

; -------------------------------------------------
; Hotkey
; -------------------------------------------------
$on = 0
HotKeySet("{F1}", "On")
HotKeySet("{F2}", "Off")
While 1
    Sleep(100)
WEnd

Func Off()
    For $X = 0 To 9
        HotKeySet($X)
    Next
EndFunc  ;==>Off



Func On()
    For $X = 0 To 9
        HotKeySet($X, "Send" & $X)
    Next
EndFunc  ;==>On

Func Send0()
    Send("{NumPad0}")
EndFunc  ;==>Send0


Func Send1()
    Send("{NumPad1}")
EndFunc  ;==>Send1


Func Send2()
    Send("{NumPad2}")
EndFunc  ;==>Send2


Func Send3()
    Send("{NumPad3}")
EndFunc  ;==>Send3


Func Send4()
    Send("{NumPad4}")
EndFunc  ;==>Send4


Func Send5()
    Send("{NumPad5}")
EndFunc  ;==>Send5


Func Send6()
    Send("{NumPad6}")
EndFunc  ;==>Send6


Func Send7()
    Send("{NumPad7}")
EndFunc  ;==>Send7


Func Send8()
    Send("{NumPad8}")
EndFunc  ;==>Send8


Func Send9()
    Send("{NumPad9}")
EndFunc  ;==>Send9
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

First of all, if you use the beta, you can totally optimize that code. Second, you CAN use A and B as hotkeys.

Try this:

#include <GUIConstants.au3>

; -------------------------------------------------
; Window
; -------------------------------------------------
GUICreate("test", 180, 130)
GUISetState()

; -------------------------------------------------
; Label
; -------------------------------------------------

GUICtrlCreateLabel("test", 5, 103)

; -------------------------------------------------
; Hotkey
; -------------------------------------------------

HotKeySet("a", "On")
HotKeySet("b", "Off")
While 1
    Sleep(100)
WEnd

Func Off()
    For $i = 0 To 9
        HotKeySet($i)
    Next
EndFunc ;==>Off

Func On()
    For $i = 0 To 9
        HotKeySet($i, "SendNumpad")
    Next
EndFunc ;==>On

Func SendNumpad()
    Send("{NumPad" & @HotKeyPressed & "}")
EndFunc ;==>SendNumpad
Link to comment
Share on other sites

Second, you CAN use A and B as hotkeys.

when was this limitation removed???

P.S. Wow!! That is some sleek looking code Saunders.

Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
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...