hadif Posted June 16, 2012 Share Posted June 16, 2012 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 16, 2012 Moderators Share Posted June 16, 2012 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 <<<<<<<<<<<<<<<<< WEndI 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
hadif Posted June 17, 2012 Author Share Posted June 17, 2012 (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 June 17, 2012 by hadif Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2012 Moderators Share Posted June 17, 2012 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 nothingThe 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 hotkeysIf 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
hadif Posted June 17, 2012 Author Share Posted June 17, 2012 - 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? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2012 Moderators Share Posted June 17, 2012 hadif, If the letter was last letter in the word then write another letterThat 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
hadif Posted June 17, 2012 Author Share Posted June 17, 2012 (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 June 17, 2012 by hadif Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2012 Moderators Share Posted June 17, 2012 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: expandcollapse popup#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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
hadif Posted June 17, 2012 Author Share Posted June 17, 2012 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: expandcollapse popup#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 Link to comment Share on other sites More sharing options...
amin84 Posted July 6, 2012 Share Posted July 6, 2012 Tnx for this. I'm making the on screen keyboard part of my Persian Unicode converter and this is VERY helpful. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2012 Moderators Share Posted July 6, 2012 leomoon, I'm making the on screen keyboardIf 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
amin84 Posted July 7, 2012 Share Posted July 7, 2012 Tnx for the link. I'll check. 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 Link to comment Share on other sites More sharing options...
amin84 Posted July 7, 2012 Share Posted July 7, 2012 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now