Sign in to follow this  
Followers 0
hadif

Hotkeys and Send problem

13 posts in this topic

Hello

Today i tried to make an applcation in AutoIt, and i have finished it.

Here is the code:

hotkeyset("{j}" , "j")
Func j()
    send ("k")
EndFunc

   hotkeyset("{k}" , "k")
Func k()
    send ("o")
EndFunc

   hotkeyset("{l}" , "l")
Func l()
    send ("e")
EndFunc

while 1
sleep (5)
Wend

If pressed " j " then it must send " k ", but when pressing j it will send " o " because of the hotkey "k"

Is there a way to fix this?

Making it if pressed " j " then send " k " not " o "

Thanks

Share this post


Link to post
Share on other sites



hadif,

Just unset/reset the other HotKey as you enter/leave the function: ;)

HotKeySet("j", "j") ; No need for { } here <<<<<<<<<<<<<<
Func j()
    HotKeySet("k")   ; Unset HotKey <<<<<<<<<<<<<<<<<<<<<<<
    Send("k")
    HotKeySet("k", "k") ; Reset HotKey <<<<<<<<<<<<<<<<<<<
EndFunc   ;==>j

HotKeySet("k", "k")
Func k()
    Send("o")
EndFunc   ;==>k

HotKeySet("l", "l")
Func l()
    Send("e")
EndFunc   ;==>l

While 1
    Sleep(10)  ; Use 10 as a minimum here <<<<<<<<<<<<<<<<<
WEnd

I added a couple of other comments as well. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thank you worked!

How to make if wrote "j" last letter of the word then write "L"?

And how to make if ON then write and if Off then do nothing.

-----

How to make they key work in the hotkeys ' ?

Edited by hadif

Share this post


Link to post
Share on other sites

hadif,

How to make if wrote "j" last letter of the word then write "L"?

I do not understand what you mean. ;)

how to make if ON then write and if Off then do nothing

The easiest way is to use another HotKey to set/clear a flag: :)

; Create a flag
Global $fRunHotKey = True

; Set a HotKey to toggle the flag
HotKeySet("{PAUSE}", "_Pause")

; And here is the HotKey we are modifying
HotKeySet("a", "_a")

While 1
    Sleep(10)
WEnd

Func _Pause()
    ; Toggle the flag
    $fRunHotKey = Not $fRunHotKey
    ; And show its state
    ConsoleWrite("Run HotKey: " & $fRunHotKey & @CRLF)
EndFunc

Func _a()
    ; Look at the flag state
    If $fRunHotKey Then
        ; Run the function
        MsgBox(0, "HotKey", "Functioning")
    Else
        ; Return immediately
        Return
    EndIf
EndFunc

How to make they key work in the hotkeys

If you need to use the HotKey itself within the function it calls, then just do as I showed earlier and unset/reset the HotKey as you enter/leave the function. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

- I do not understand what you mean. ;)

If the letter was last letter in the word then write another letter.

--------------------------------------------

This keys does not working in the hotkeyset ( [ and ] and ' and ; ....... )

How can i make it work?

Share this post


Link to post
Share on other sites

hadif,

If the letter was last letter in the word then write another letter

That is a whole new problem. How do you expect AutoIt to know it is the last letter of a word? In which application are you using these HotKeys? ;)

This keys does not working in the hotkeyset ( [ and ] and ' and ; ....... )

They work for me. What keyboard layout do you have? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hmm so i can't do if the letter was last letter in the word then..

What do you mean in waht keybord layout do you have? Language? if language then English

Okay , this is the final code , and i'm still getting errors:

#Include <Misc.au3>
Local $on = ""
If _IsPressed("F9") Then
$on = 1
ElseIf _IsPressed("F8") Then
$on = 0
EndIf
If $on = 1 Then  
HotKeySet("j", "j")
Func j()
    HotKeySet("k")
    Send("k")
    HotKeySet("k", "k")
EndFunc
HotKeySet("k", "k")
Func k()
    Send("o")
EndFunc
HotKeySet("l", "l")
Func l()
    Send("e")
EndFunc
ElseIf $var < 0 Then ; Do nothing
   Else
   MsgBox(4096, "Typer Crashed", "Please report about your problem to fix it")
EndIf
While 1
    Sleep(10)
WEnd
Edited by hadif

Share this post


Link to post
Share on other sites

hadif,

There is so much wrong with that code that I do not know where to start. Take a look at this version (which does work) and see if you can see why I have changed it: :)

#include <Misc.au3>

Global $on = 1  ; This is the variable you toggle
Global $iState = 0 ; This checks if the state of that variable has changed
Global $hDLL = DllOpen("user32.dll") ; We are calling _IsPressed in a loop so open the DLL

HotKeySet("{ESC}", "On_Exit") ; This allows us to exit gracefully

While 1
    ; Keep the CPU cool
    Sleep(10)
    ; Toggle the variable
    If _IsPressed("78", $hDLL) Then ; If you want the F9 key here then use the correct keycode
        $on = 1
    ElseIf _IsPressed("77", $hDLL) Then ; If you want the F8 key here then use the correct keycode
        $on = 0
    EndIf
    ; Check if the state has changed - otherwise we run this every pass through the loop jjkkk
    If $on <> $iState Then
        ; It has so set the correct state
        $iState = $on
        If $iState = 1 Then
            ; Set the HotKeys
            HotKeySet("j", "j")
            HotKeySet("k", "k")
            HotKeySet("l", "l")
        Else
            ; Unset the HotKeys
            HotKeySet("j")
            HotKeySet("k")
            HotKeySet("l")
        EndIf
    EndIf
WEnd

; Declare functions OUTSIDE the loop
Func j()
    HotKeySet("k")
    Send("k")
    HotKeySet("k", "k")
EndFunc   ;==>j

Func k()
    Send("o")
EndFunc   ;==>k

Func l()
    Send("e")
EndFunc   ;==>l

Func On_Exit()
    ; And closee the DLL as we exit
    DllClose($hDLL)
    Exit
EndFunc

Please ask if you have any questions. :)

By the way, what is this "Typer" supposed to do? ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

hadif,

There is so much wrong with that code that I do not know where to start. Take a look at this version (which does work) and see if you can see why I have changed it: :)

#include <Misc.au3>

Global $on = 1  ; This is the variable you toggle
Global $iState = 0 ; This checks if the state of that variable has changed
Global $hDLL = DllOpen("user32.dll") ; We are calling _IsPressed in a loop so open the DLL

HotKeySet("{ESC}", "On_Exit") ; This allows us to exit gracefully

While 1
    ; Keep the CPU cool
    Sleep(10)
    ; Toggle the variable
    If _IsPressed("78", $hDLL) Then ; If you want the F9 key here then use the correct keycode
        $on = 1
    ElseIf _IsPressed("77", $hDLL) Then ; If you want the F8 key here then use the correct keycode
        $on = 0
    EndIf
    ; Check if the state has changed - otherwise we run this every pass through the loop jjkkk
    If $on <> $iState Then
        ; It has so set the correct state
        $iState = $on
        If $iState = 1 Then
            ; Set the HotKeys
            HotKeySet("j", "j")
            HotKeySet("k", "k")
            HotKeySet("l", "l")
        Else
            ; Unset the HotKeys
            HotKeySet("j")
            HotKeySet("k")
            HotKeySet("l")
        EndIf
    EndIf
WEnd

; Declare functions OUTSIDE the loop
Func j()
    HotKeySet("k")
    Send("k")
    HotKeySet("k", "k")
EndFunc   ;==>j

Func k()
    Send("o")
EndFunc   ;==>k

Func l()
    Send("e")
EndFunc   ;==>l

Func On_Exit()
    ; And closee the DLL as we exit
    DllClose($hDLL)
    Exit
EndFunc

Please ask if you have any questions. :)

By the way, what is this "Typer" supposed to do? ;)

M23

Just testing something

Thank you,, worked

Share this post


Link to post
Share on other sites

leomoon,

I'm making the on screen keyboard

If you are working with virtual keyboards, you might find this thread of interest. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Tnx for the link. I'll check. :D

One question. The new keyboard mapping I'm doing is for Persian. And because it's RTL, Shift+9 is ")" and Shift+0 is "(" also the rest of the brackets are reversed and some are mapped on another button... I mapped every single Persian alphabet and they all work perfect. But if the character exists in English keyboard, it won't assign it to another key.

Global $hDLL=DllOpen('user32.dll')

HotKeySet('{ESC}', '_exit')

While 1
Sleep(10)
_setParsi()
WEnd

Func _setParsi()
HotKeySet('+9','_9Sft')
HotKeySet('+0','_0Sft')
EndFunc

Func _9Sft()
Send(')')
EndFunc
Func _0Sft()
Send('(')
EndFunc

Share this post


Link to post
Share on other sites

Here is the fixed code. Shift+9 and Shift+0 are swapped for RTL languages. You can do the same for {, }, [, ], < and >...:

Global $hDLL=DllOpen('user32.dll')

HotKeySet('{ESC}', '_exit')

While 1
Sleep(10)
_setParsi()
WEnd

Func _setParsi()
HotKeySet('+9','_9Sft')
HotKeySet('+0','_0Sft')
EndFunc

Func _9Sft()
HotKeySet('+9')
HotKeySet('+0')
Send('+0')
HotKeySet('+9','_9Sft')
HotKeySet('+0','_0Sft')
EndFunc
Func _0Sft()
HotKeySet('+9')
HotKeySet('+0')
Send('+9')
HotKeySet('+9','_9Sft')
HotKeySet('+0','_0Sft')
EndFunc

Func _exit()
DllClose($hDLL)
Exit
EndFunc

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
Sign in to follow this  
Followers 0