Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Input detect once  (Read 7046 times)

0 Members and 1 Guest are viewing this topic.

TheYoungGeek43

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Input detect once
« on: August 26, 2018, 09:38:41 am »
Hello

I've problem my problem is I want when player pressed the left button of mouse my game detect one clic not 3600 clic

Thanks for your help ;)
L'échec est la preuve que l'on à essayer

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Input detect once
« Reply #1 on: August 26, 2018, 09:51:29 am »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

TheYoungGeek43

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Input detect once
« Reply #2 on: August 26, 2018, 10:05:23 am »
Hi
I've see that in internet but I don't understand where i initialize the Event in my main class i just this
                Window.DispatchEvents();
 
For the event
L'échec est la preuve que l'on à essayer

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Input detect once
« Reply #3 on: August 26, 2018, 10:08:35 am »
I apologise; I didn't notice that this was in the DotNet category.
I have little experience with C# so I'm unsure as the correct way to approach this situation and how it may be different from the C++ approach.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

TheYoungGeek43

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Input detect once
« Reply #4 on: October 05, 2018, 08:58:34 am »
Hello

I've surrend this idea but this week i take my revenche but i don't know how I can do this

I want detect just once the input for detect the input always is pressed i use
            _window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
 
        private static void OnKeyPressed(object sender, KeyEventArgs e)
        {
            Window window = (Window)sender;
            if (e.Code == Keyboard.Key.A)
                Console.WriteLine("Hola");
        }
 

But i don't find for detect the input once

I'm french sorry for my english ;)

Thanks for your help ;)
L'échec est la preuve que l'on à essayer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Input detect once
« Reply #5 on: October 05, 2018, 10:00:18 am »
The Window class has a function to disable repeated keyboard events.
Laurent Gomila - SFML developer

TheYoungGeek43

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Input detect once
« Reply #6 on: October 05, 2018, 03:02:33 pm »
Ok but if i want detected the repeat i can't
Because i wan't to detected once for the attack but for the move i want detected always :/
L'échec est la preuve que l'on à essayer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Input detect once
« Reply #7 on: October 05, 2018, 03:08:38 pm »
Moves should use real-time inputs (Keyboard and Mouse classes), not events.
Laurent Gomila - SFML developer

billarhos

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Input detect once
« Reply #8 on: October 05, 2018, 03:19:39 pm »
You can keep read repeatedly your key strokes and implement your "attack" with toggling a boolean  on key down and key up event.

TheYoungGeek43

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Input detect once
« Reply #9 on: October 06, 2018, 08:53:50 am »
Hello

I write the
            window.SetKeyRepeatEnabled(false);
 
But this don't work i try to write in the Update, in the constructor of my main class, in my function OnKeyPressed and in my function for create my window but this line don't work :/

Where i write i don't find.

Thanks and sorry :/
L'échec est la preuve que l'on à essayer

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Input detect once
« Reply #10 on: October 06, 2018, 09:17:19 pm »
Can you provide a minimal example?

TheYoungGeek43

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Input detect once
« Reply #11 on: October 07, 2018, 01:36:32 pm »
Sure sorry
OnKeyPressed function
        private void OnKeyPressed(object sender, KeyEventArgs e)
        {
            Window window = (Window)sender;
            window.SetKeyRepeatEnabled(false);
            if (e.Code == Keyboard.Key.A)
            {
                Console.WriteLine("Bou");
            }
        }
 

Update function
private void Update()
{
            _window.Closed += new EventHandler(OnClosed);
            _window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            _window.SetFramerateLimit(60);
}
 

The Update function is call when i do the while window.isOpen

Thanks
L'échec est la preuve que l'on à essayer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Input detect once
« Reply #12 on: October 07, 2018, 08:22:59 pm »
People usually put a link under "minimal example", please click and read it...

Your Update() function does stuff that should be done just once, I hope you don't call it every frame (and if you don't, then you should rename it). Also don't call SetKeyRepeatEnabled every time, do it just once.
Laurent Gomila - SFML developer

 

anything