Jump to content

Is there any better way to do this ?


Recommended Posts

Hi all,

I want use more than one key in HotKeySet or _IsPressed functions. This is my code. It is working. But i would like to know if there is any better way to do this.

Local $flag1 = False
Local $flag2 = False

While 1
    Sleep(10)
    if _IsPressed("4D") Then $flag1 = True
    If _IsPressed("44") Then $flag2 = True
    if  $flag1 = True And $flag2 = True And _IsPressed("41") Then TestSend()
WEnd

Func TestSend()
    Send("{BS 3}My Dear Alan{TAB}:{SPACE}")
EndFunc   ;==>WordSendKeyALT_W
Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Here's how I'd do it.  Your mileage may vary.

#include <Misc.au3>

Const $ip_m = "4D"
Const $ip_d = "44"
Const $ip_a = "41"

Do
    If _IsPressed($ip_m) And _IsPressed($ip_d) And _IsPressed($ip_a) Then
        TestSend()    

        Do
            Sleep(100)
        Until Not _IsPressed($ip_m) Or Not _IsPressed($ip_d) Or Not _IsPressed($ip_a)
    EndIf
    
    Sleep(100)
Until False

Func TestSend()
    Send("{BS 3}My Dear Alan{TAB}:{SPACE}")
EndFunc
Edited by jaberwacky
Link to comment
Share on other sites

the OP sets "a" to type that string, everytime, after "m" and "d" have been pressed.  So thats probably not desirable without setting those flags back to False after the send, requiring them to be subsequent, or requiring all three to be pressed as in Jab's.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Hi, 

boththose You are right. jaberwacky's code is not working for me.
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Hi 

jaberwacky, This is my goal => When i pressed 'a' right after 'md', then the text will be 'mda'. Then my script suddenly replaces that 'mda' with 'My dear alan'.
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

not an inference, just stating what that code does differently...

Do you want that behavior?  because if you start your script in post #1 and type "mom and dad" you will get "mom andMy Dear Alan: "

if you want it to work as though it is exploding the abbreviation "mda", you may want to look at hotstrings

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

concur, use manadar's stuff, I edited his example to perform your task

; Authors: Manadar, GarryFrost
; Contributor: WideBoyDixon

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

#include-once

Dim $hHook
Dim $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
Dim $hmod = _WinAPI_GetModuleHandle(0)
Dim $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
Dim $buffer = ""
Dim $hotstrings[1]
Dim $hotfuncs[1]
Dim $hWnd = GUICreate("")
GUIRegisterMsg($WM_KEYDOWN, "_GUIKeyProc")

;; ==========================
;; This is your actual script.
;; ==========================

;#include <HotString.au3>

HotStringSet("mda","examplefunction")

While 1
    Sleep(10)
WEnd

Func examplefunction()
    Send("{BACKSPACE 3}")
    Send("My Dear Alan: ")
EndFunc


;; ==========================
;; End of actual script.
;; The part above the start of the actual script
;; and below this comment
;; script can be put in another
;; file and included.
;; ==========================

Func HotStringSet($hotstring, $func)
    _ArrayAdd($hotstrings, $hotstring)
    _ArrayAdd($hotfuncs, $func)
EndFunc

Func EvaluateKey($keycode)
    If (($keycode > 64) And ($keycode < 91)) _ ; A - Z
            Or (($keycode > 47) And ($keycode < 58)) Then ; 0 - 9
        $buffer &= Chr($keycode)
        $buffer = StringRight($buffer, 50)

        _CheckHotkeys($buffer)
    EndIf
EndFunc   ;==>EvaluateKey

Func _CheckHotkeys($s)
    For $i = 0 to UBound($hotstrings)-1
        if ( $hotstrings[$i] = StringRight($s, StringLen($hotstrings[$i])) ) Then
            Call($hotfuncs[$i])
        EndIf
    Next
EndFunc

Func _GUIKeyProc($hWnd, $Msg, $wParam, $lParam)
    EvaluateKey(Number($wParam))
EndFunc

;===========================================================
; callback function. This function must return as quickly as possible or it will stall and block user input
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        $vkKey = DllStructGetData($tKEYHOOKS, "vkCode")
        _WinAPI_PostMessage($hWnd, $WM_KEYDOWN, $vkKey, 0)
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc   ;==>OnAutoItExit
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Hi 

boththose, At the first look, my mind said that "this is the code i am searching for". Becaude, i need to write a script which contains "WM_COMMAND" and SetWindowsHookEx. But i don't know how to use the setwindowshookex function. Anyhow, this should be a great help for me. Thank you very much. :) But i didn't tested this code yet. I will inform you after that.  :thumbsup: 
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

×
×
  • Create New...