tsue Posted April 28, 2010 Posted April 28, 2010 hello, i have been doing a program and i have a problem in this part of the program. i need to save marie in a txt file once for every a pressed but i need to do it with this coding #include <Misc.au3> #include <Process.au3> While 1 $key = _Isenter(1) If $key Then FileWrite("new.txt", $key) WEnd Func _Isenter($UseNames = 0) $names = ("marie") If _IsPressed(41) Then If $UseNames Then Return $names Else Return 1 EndIf EndIf EndFunc any help will be apretiated. thanks
Moderators Melba23 Posted April 28, 2010 Moderators Posted April 28, 2010 tsue,I presume your problemis that you are getting multiple "marie"s each time you press "a". You need to wait until the "a" key is released before returning from the function. Your PC is so fast that even the most rapid keypress will result in multiple hits on the function.It is easy to do: #include <Misc.au3> #include <Process.au3> While 1 $key = _Isenter(1) If $key Then FileWrite("new.txt", $key) WEnd Func _Isenter($UseNames = 0) $names = ("marie") If _IsPressed(41) Then While _IsPressed(41) Sleep(10) WEnd If $UseNames Then Return $names Else Return 1 EndIf EndIf Sleep(10) EndFunc ;==>_IsenterI have also added some Sleep statements to keep your CPU from maxing out. I hope this helps. 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
PsaltyDS Posted April 28, 2010 Posted April 28, 2010 (edited) Why just like that? It's an absurd way to perform that function. Why not just: While 1 If _IsPressed("41") Then FileWrite("new.txt", "marie") Sleep(500) WEnd Or is the real intent to log lots of keys, or even all of them... Edited April 28, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
tsue Posted April 28, 2010 Author Posted April 28, 2010 tsue, I presume your problemis that you are getting multiple "marie"s each time you press "a". You need to wait until the "a" key is released before returning from the function. Your PC is so fast that even the most rapid keypress will result in multiple hits on the function. It is easy to do: #include <Misc.au3> #include <Process.au3> While 1 $key = _Isenter(1) If $key Then FileWrite("new.txt", $key) WEnd Func _Isenter($UseNames = 0) $names = ("marie") If _IsPressed(41) Then While _IsPressed(41) Sleep(10) WEnd If $UseNames Then Return $names Else Return 1 EndIf EndIf Sleep(10) EndFunc ;==>_Isenter I have also added some Sleep statements to keep your CPU from maxing out. I hope this helps. M23 thanks for the help, it worked the only thing i notice was that if i let the a pressed it will only write marie once its not really that i need it to write multiple times as i press the a but how could i make it work that way to the melba thanks for the help too and im not trying to log keys im tring log names like shorkcuts in this scrip
Moderators Melba23 Posted April 28, 2010 Moderators Posted April 28, 2010 tsue,i need it to write multiple times as i press the aYour script already wrote multiple "marie"s to the file - did you even look? And do not confuse me with the rakishly good-looking water fowl - we are birds of a very different feather! 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
tsue Posted April 28, 2010 Author Posted April 28, 2010 tsue,Your script already wrote multiple "marie"s to the file - did you even look? And do not confuse me with the rakishly good-looking water fowl - we are birds of a very different feather! M23yes i checked im sorry if i didnt express correctlyok the thing ive notice is if i press a it will write marie only once, with my old program it writes multiple mariesbut if i let the a pressed like for 5 seconds it will only write marie once, i was yust asking if it can work more like a normal way, its not really neccesary but i like programs to be made really goodexampleaaaaaaaaaaaaaaaaaaaaaaaaaa i let the a pressed for about 3 seconds there were 25 a's so there will be 25 marie so it can act with a normal behaviorthanks
Moderators Melba23 Posted April 29, 2010 Moderators Posted April 29, 2010 tsue,The easiest way to get your key to do that is to use a HotKey - then you get the normal typematic repeat behaviour, which seems to be what you want: HotKeySet("{ESC}", "On_Exit") HotKeySet("a", "new_a") Global $iCount = 0 While 1 Sleep(10) WEnd Func new_a() $iCount += 1 ConsoleWrite("marie " & $iCount & @CRLF) ;FileWrite("new.txt", "marie") EndFunc Func On_Exit() Exit EndFuncI used ConsoleWrite so you could see what is going on - just delete that line (and the lines dealing with $iCount) and uncomment the FileWrite line when you want it to write to the file.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
tsue Posted April 29, 2010 Author Posted April 29, 2010 tsue, The easiest way to get your key to do that is to use a HotKey - then you get the normal typematic repeat behaviour, which seems to be what you want: HotKeySet("{ESC}", "On_Exit") HotKeySet("a", "new_a") Global $iCount = 0 While 1 Sleep(10) WEnd Func new_a() $iCount += 1 ConsoleWrite("marie " & $iCount & @CRLF) ;FileWrite("new.txt", "marie") EndFunc Func On_Exit() Exit EndFunc I used ConsoleWrite so you could see what is going on - just delete that line (and the lines dealing with $iCount) and uncomment the FileWrite line when you want it to write to the file. M23 thanks, im now using hotkey, is the form to diference a from A when caps if active in hotkeys so that if i press a it writes marie and if i press A marie aria montaqiu
Moderators Melba23 Posted April 29, 2010 Moderators Posted April 29, 2010 tsue,When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. Search the forum for "+detect +caps +lock" - there are lots of examples. And if you want to know if the shift key is down, just use _IsPressed a second time. Time for you to do some work now - come back if you run into difficulty. 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
tsue Posted April 29, 2010 Author Posted April 29, 2010 (edited) hello, thanks for all the help i found a way to If _GetCapsLock() Then MsgBox(0, "Key State", "Caps Lock is On") Func _GetCapsLock() Local $ret $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_CAPITAL) Return $ret[0] EndFunc i have doubt is it possible to active more than one isactive like if i press a followed by a b it writes marie you have misstyped i tried this but i cant make it work While 1 If _IsPressed("41") & _IsPressed("42") Then MsgBox(0,"error", "misstyped") EndIf Sleep(100) Wend Edited April 29, 2010 by tsue
Moderators Melba23 Posted April 30, 2010 Moderators Posted April 30, 2010 tsue,First, go and check the syntax for AND - you will find it under <Language Reference - Operators>. A hint - it is not &. Anyway, you need something like this:#include <Misc.au3> Global Const $VK_CAPITAL = 0x14 While 1 If _IsPressed("41") Then If _IsPressed("10") Or _GetCapsLock() Then ConsoleWrite("marie aria montaqiu" & @CRLF) Else ConsoleWrite("marie" & @CRLF) EndIf EndIf Sleep(10) Wend Func _GetCapsLock() Local $ret $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_CAPITAL) Return $ret[0] EndFuncM23 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
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