Jump to content
Sign in to follow this  
tsue

save in a file "marie" only once per key a

Recommended Posts

tsue

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

Share this post


Link to post
Share on other sites
Melba23

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: :idea:

#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


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
PsaltyDS

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...

:idea:

Edited 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

Share this post


Link to post
Share on other sites
tsue

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: :idea:

#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

Share this post


Link to post
Share on other sites
Melba23

tsue,

i need it to write multiple times as i press the a

Your script already wrote multiple "marie"s to the file - did you even look? :idea:

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._______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
tsue

tsue,

Your script already wrote multiple "marie"s to the file - did you even look? :idea:

And do not confuse me with the rakishly good-looking water fowl - we are birds of a very different feather! :)

M23

yes i checked im sorry if i didnt express correctly

ok the thing ive notice is if i press a it will write marie only once, with my old program it writes multiple maries

but 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 good

example

aaaaaaaaaaaaaaaaaaaaaaaaaa

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 behavior

thanks

Share this post


Link to post
Share on other sites
Melba23

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: :idea:

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


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
tsue

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: :idea:

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

Share this post


Link to post
Share on other sites
Melba23

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. :idea:

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._______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
tsue

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 by tsue

Share this post


Link to post
Share on other sites
Melba23

tsue,

First, go and check the syntax for AND - you will find it under <Language Reference - Operators>. A hint - it is not &. :idea:

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]
EndFunc

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.