USB mouse disconnects, and reconnection is not successful

A Logitech Gaming Mouse G400 keeps disconnecting randomly. In the event reported below, it disconnected after 5.9 hours.

I have already:

  • disassembled the mouse and pulled the cord a few centimeters into the mouse

  • blacklisted the mouse from usb autosuspending:

    # in /etc/udev/rules.d/50-usb_power_save.rules
    # blacklist for usb autosuspend
    ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", GOTO="power_usb_rules_end"
    ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"
    LABEL="power_usb_rules_end"   
    
  • set the Kernel boot parameters: acpi=off and usbcore.autosuspend=-1

/var/log/Xorg.0.log reports

( 21216.637) (II) config/udev: removing device Logitech Gaming Mouse G400
( 21216.637) (II) event1  - Logitech Gaming Mouse G400: device removed
( 21216.715) (II) UnloadModule: "libinput"

and dmesg reports

(21217.938985) usb 1-2: USB disconnect, device number 2
(21219.088604) usb usb1-port2: Cannot enable. Maybe the USB cable is bad?
(21219.216597) usb 1-2: new full-speed USB device number 7 using xhci_hcd
(21219.828647) usb 1-2: device descriptor read/64, error -71
(21220.756698) usb 1-2: device descriptor read/64, error -71
(21220.864727) usb usb1-port2: attempt power cycle
(21221.792756) usb 1-2: new full-speed USB device number 8 using xhci_hcd
(21221.792877) usb 1-2: Device not responding to setup address.
(21222.000895) usb 1-2: Device not responding to setup address.
(21222.208774) usb 1-2: device not accepting address 8, error -71
(21222.612804) usb 1-2: new full-speed USB device number 9 using xhci_hcd
(21222.612907) usb 1-2: Device not responding to setup address.
(21222.820919) usb 1-2: Device not responding to setup address.
(21223.028823) usb 1-2: device not accepting address 9, error -71
(21223.028867) usb usb1-port2: unable to enumerate USB device

Thicker part of the cable located in the bend has indeed deteriorated, but pulling the cord a few centimeters into the mouse seems to have fixed it; if I disconnect from the USB port and reconnect, the mouse work again. Moreover, even if there is still some problem with the cable, it seems from the dmesg report above that it goes back quickly to its place, and a reconnection is tried.

Why isn’t the reconnection reported by dmesg successful, and what can be done about it?

javascript – EMITIR SOM, QUANDO O MOUSE FOR PASSADO POR CIMA DO CAMPO

Galera, alguém me da um help.

Estou criando uma tela de login bem simples, gostaria que quando o usuario passa-se o mouse em cima do campo “e-mail” ou “senha”, fizesse um som simples.

quero baixar esse toquinho, para quando o usuario passar o mouse em cima do campo, ele tocar: http://youtube.com/watch?v=b1nFfKCMPac

.box {
  width: 400px;
  height: 350px;
  position: absolute;
  top: 58%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgb(115, 254, 255);
  background: linear-gradient(295deg, rgba(115, 254, 255, 1) 8%, rgba(108, 194, 255, 1) 66%);
  align-items: center;
  text-align: center;
  border-radius: 20px;
  box-shadow: 0 0 8px 3px rgb(34, 34, 34);
}

.box h1 {
  font-size: 2.8rem;
  color: #050505;
  text-transform: uppercase;
  font-weight: bolder;
  font-family: 'DotGothic16', sans-serif;
  letter-spacing: 2px;
}

.box input(type="text"),
.box input(type="Senha") {
  border: 0;
  background: none;
  display: block;
  margin: 15px auto;
  text-align: center;
  border: 2px solid #000000;
  padding: 14px 10px;
  outline: none;
  color: rgb(0, 0, 0);
  border-radius: 10px;
  font-weight: bolder;
  font-family: 'Montserrat', sans-serif;
}

.box input(type="text"):hover,
.box input(type="Senha") {
  width: 200px;
  border-color: rgb(255, 255, 255);
}

.btn {
  border: 0;
  background: none;
  margin: 20px auto;
  text-align: center;
  border: 2px solid #2ecc71;
  padding: 10px 40px;
  outline: none;
  color: rgb(0, 0, 0);
  border-radius: 24px;
  transition: 0.25s;
  cursor: pointer;
  font-weight: bold;
}

.btn:hover {
  background: #2ecc71;
}
<!DOCTYPE html>
<html lang="pt-br">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css">
  <link rel="shortcut icon" href="./img/puzzle.png" type="image/x-icon">
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=DotGothic16&family=Montserrat&display=swap" rel="stylesheet">

  <title>Brain | Login</title>
</head>

<body>

  <form action="index.html" class="box" method="post">
    <h1>Login</h1>
    <audio src="https://pt.stackoverflow.com/mario-song.mp4"></audio>

    <!--OS CAMPOS INPUT, SÃO OS DO E-MAIL E SENHA DE LOGIN-->
    <!--COLOCAR UM SOM SIMPLES PARA QUANDO O USUARIO PASSAR O MOUSE, TOCAR-->
    <input type="text" name="" placeholder="E-mail">
    <input type="text" name="" placeholder="Senha">

    <button class="btn">Entrar</button>
  </form>

</body>

</html>

Tela de login

hang – BigSur – unresponsive dialogs to mouse actions

Sometimes at the beginning of the year 2021, I started to have a problem with the “File upload” dialogs in the web browser. The dialog is unresponsive to the mouse. I can use the keyboard for navigation, but the Tab key only switch between the left panel and the “Search” field and I’m unable to focus the main area with files, thus I’m unable to select one, but I can escape that dialog with Esc and, as this regards also “Save as” dialogs, I’m able to select some directory in left panel’s “Favorites” and confirm with Enter.

As time passes, I realized, that this problem applies to almost all native dialogs. I’m currently unable to open e.g. Pages or Textedit, as it starts with the “File open” dialog, which I’m unable to handle.

And yesterday, I needed to tweak some configuration in “Security & Privacy” in “System Preferences” and I realized it has the same symptoms. I can click on the top navigation panel and return back to the “System Preferences” main screen, but I’m unable to click on anything in the “Security & Privacy” main section. The keyboard navigation works, but, again, the Tab key only switches between the left list and the “Search” field, and I’m unable to click on “Click the lock to make changes” so, it’s all helpless.

I googled for similar issues, but so far found nothing heplful.

Does anyone have some idea where to look, what to try?

performance – Python pynput keyboard + mouse input printer

I needed to have input shown for some things in a game I play on Linux, but Linux doesn’t seem to have any good input display programs. I decided it would be good enough to have python print to a pair of xterm windows (one for keyboard and one for mouse) using pynput. I do this using two different python programs because the only way I found to have one python programs deal with two terminals is to constantly write to a file and use tail -f, and I didn’t want to do that.

Because both programs ended up being so small and simple, I tried to write it so that the key/mouse listeners would run their functions as fast as possible. But I might have missed some things that could be done. I’m wondering if anyone knows of any other ways to optimize this for response time. I know it won’t make anything close to a noticeable difference, I’m just asking out of curiosity.

*Edited because I thought of ways to make it faster

mouse_listener.py

from pynput import mouse

def main():
    
    print_count = 0
    
    def on_click(x,
        y,
        button,
        pressed,
        local_print=print,
        dashes="--- ",
        no_dashes="    ",
        pressed_str=" mouse pressed",
        released_str=" mouse released"
        ):
        nonlocal print_count
        if print_count >= 10:
            if pressed:
                local_print(dashes + button.name + pressed_str)
                print_count = 0
            else:
                local_print(dashes + button.name + released_str)
                print_count = 0
        else:
            if pressed:
                local_print(no_dashes + button.name + pressed_str)
                print_count = print_count + 1
            else:
                local_print(no_dashes + button.name + released_str)
                print_count = print_count + 1
    
    def on_scroll(x,
        y,
        dx,
        dy,
        local_print=print,
        dashes="--- ",
        no_dashes="    ",
        up_str="scroll up",
        down_str="scroll down"
        ):
        nonlocal print_count
        if print_count >= 10:
            if dy == 1:
                local_print(dashes + up_str)
                print_count = 0
            else:
                local_print(dashes + down_str)
                print_count = 0
        else:
            if dy == 1:
                local_print(no_dashes + up_str)
                print_count = print_count + 1
            else:
                local_print(no_dashes + down_str)
                print_count = print_count + 1
    
    try:
        listener = mouse.Listener(on_click=on_click, on_scroll=on_scroll)
        listener.start()
        listener.join()
    except KeyboardInterrupt:
        listener.stop()

main()

key_listener.py

from pynput import keyboard

def main():
    
    print_count = 0
    held = set()
    
    def on_press(key,
        local_print=print,
        local_hasattr=hasattr,
        held_local=held,
        hold=held.add,
        str_lower=str.lower,
        dashes="--- ",
        no_dashes="    ",
        end_text=" pressed",
        str_for_hasattr="name"
        ):
        nonlocal print_count
        if key not in held_local:
            if local_hasattr(key, str_for_hasattr):
                if print_count >= 10:
                    local_print(dashes + key.name + end_text)
                    print_count = 0
                else:
                    local_print(no_dashes + key.name + end_text)
                    print_count = print_count + 1
            else:
                if print_count >= 10:
                    local_print(dashes + str_lower(key.char) + end_text)
                    print_count = 0
                else:
                    local_print(no_dashes + str_lower(key.char) + end_text)
                    print_count = print_count + 1
            hold(key)
    
    def on_release(key,
        local_print=print,
        local_hasattr=hasattr,
        unhold=held.remove,
        str_lower=str.lower,
        dashes="--- ",
        no_dashes="    ",
        end_text=" released",
        str_for_hasattr="name"
        ):
        nonlocal print_count
        if local_hasattr(key, str_for_hasattr):
            if print_count >= 10:
                local_print(dashes + key.name + end_text)
                print_count = 0
            else:
                local_print(no_dashes + key.name + end_text)
                print_count = print_count + 1
        else:
            if print_count >= 10:
                local_print(dashes + str_lower(key.char) + end_text)
                print_count = 0
            else:
                local_print(no_dashes + str_lower(key.char) + end_text)
                print_count = print_count + 1
        try: # I don't trust this part
            unhold(key)
        except KeyError:
            pass
    
    try: # TypeError is possible because numpad 5's char attribute is None
        listener = keyboard.Listener(on_press=on_press, on_release=on_release)
        listener.start()
        listener.join()
    except (KeyboardInterrupt, TypeError):
        listener.stop()

main()

xterm_opener.sh

xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "keyboard" -geometry 28x16 -e python3 '/home/USERNAME/input_listener/key_listener.py' &
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "mouse" -geometry 28x16 -e python3 '/home/USERNAME/input_listener/mouse_listener.py'

performance – under 100 line Python pynput keyboard + mouse input printer

I needed to have input shown for some things in a game I play on Linux, but Linux doesn’t seem to have any good input display programs. I decided it would be good enough to have python print to a pair of xterm windows (one for keyboard and one for mouse) using pynput. I do this using two different python programs because the only way I found to have one python programs deal with two terminals is to constantly write to a file and use tail -f, and I didn’t want to do that.

Because both programs ended up being so small and simple, I tried to write it so that the key/mouse listeners would run their functions as fast as possible. But I might have missed some things that could be done. I’m wondering if anyone knows of any other ways to optimize this for response time. I know it won’t make anything close to a noticeable difference, I’m just asking out of curiosity.

mouse_listener.py

from pynput import mouse

def main():
    
    print_count = 0
    
    def on_click(x, y, button, pressed, local_print=print):
        nonlocal print_count
        try:
            if print_count >= 10:
                local_print(f"--- {button.name} mouse {'pressed' if pressed else 'released'}")
                print_count = 0
            else:
                local_print(f"    {button.name} mouse {'pressed' if pressed else 'released'}")
                print_count += 1
        except AttributeError:
            pass
    
    def on_scroll(x, y, dx, dy, local_print=print):
        nonlocal print_count
        try:
            if print_count >= 10:
                local_print(f"--- {'scroll up' if dy == 1 else 'scroll down'}")
                print_count = 0
            else:
                local_print(f"    {'scroll up' if dy == 1 else 'scroll down'}")
                print_count += 1
        except AttributeError:
            pass
    
    try:
        listener = mouse.Listener(on_click=on_click, on_scroll=on_scroll)
        listener.start()
        listener.join()
    except KeyboardInterrupt:
        listener.stop()

main()

key_listener.py

from pynput import keyboard

def main():
    
    print_count = 0
    held = set() # this is needed because it keeps calling on_press when you hold a key
    
    def on_press(key, local_print=print, held_local=held, hold=held.add, str_lower=str.lower):
        nonlocal print_count
        if key not in held_local:
            try:
                if print_count >= 10:
                    local_print(f"--- {key.name} pressed")
                    print_count = 0
                else:
                    local_print(f"    {key.name} pressed")
                    print_count += 1
            except AttributeError:
                if print_count >= 10:
                    local_print(f"--- {str_lower(key.char) if key.char is not None else 5} pressed")
                    print_count = 0
                else:
                    local_print(f"    {str_lower(key.char) if key.char is not None else 5} pressed")
                    print_count += 1
            hold(key)
    
    def on_release(key, local_print=print, unhold=held.remove, str_lower=str.lower):
        nonlocal print_count
        try:
            if print_count >= 10:
                local_print(f"--- {key.name} released")
                print_count = 0
            else:
                local_print(f"    {key.name} released")
                print_count += 1
        except AttributeError:
            if print_count >= 10:
                local_print(f"--- {str_lower(key.char) if key.char is not None else 5} released")
                print_count = 0
            else:
                local_print(f"    {str_lower(key.char) if key.char is not None else 5} released")
                print_count += 1
        try:
            unhold(key)
        except KeyError:
            pass
    
    try:
        listener = keyboard.Listener(on_press=on_press, on_release=on_release)
        listener.start()
        listener.join()
    except KeyboardInterrupt:
        listener.stop()

main()

xterm_opener.sh

xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "keyboard" -geometry 28x16 -e python3 '/home/USERNAME/input_listener/key_listener.py' &
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "mouse" -geometry 28x16 -e python3 '/home/USERNAME/input_listener/mouse_listener.py'

unity – Press and hold camera movement with mouse in new Input System?

I am transitioning to the new movement system and am having trouble figuring out how to move the camera when a mouse button is pressed and held.

Here’s how I did it before:

private void Update()
{
    // Get the position of the mouse when a middle click occurs
    if (Input.GetMouseButtonDown(2))
    {
        _dragOrigin = cam.ScreenToWorldPoint(Input.mousePosition);
    }

    // If the MMB is still held down, calculate the distance and move the camera
    if (Input.GetMouseButton(2))
    {
        Vector3 difference = _dragOrigin - cam.ScreenToWorldPoint(Input.mousePosition);
        cam.transform.position += difference;
    }
}

I have tried doing something similar in the new input system but it doesn’t work:

public void OnMMB(InputAction.CallbackContext context)
{
    if (context.phase != InputActionPhase.Started)
    {
        // Get the position of the mouse when a middle click occurs
        dragOrigin = cam.ScreenToWorldPoint(Mouse.current.position.ReadValue());
    }
    else
    {
        // If the MMB is still held down, calculate the distance and move the camera
        Vector2 newPosition = cam.ScreenToWorldPoint(Mouse.current.position.ReadValue());
        Vector3 difference = dragOrigin - newPosition;
        cam.transform.position += difference;
    }
}

Here is how I set this up inside the Input editor:
Image

The Action Type of the action is Button.

How do I disable mouse history scrolling?

How Do you disable the ability to scroll through history using the mouse scroll button. The reason that I need to do it that I am programming and I find my scroll history pasted randomly through my code. I hate it and it need to be fixed.

Mouse won’t work on USB switch

I’ve tried 2 USB switches, Rybozen USB switch and Takya USB swtich, and my mouse will not work when I switch over to my HP EliteDesk 705 G4 Mini PC.

The switches worked fine on a Mac laptop I once had and it works fine on my Lenovo ThinkPad P50.

I’ve tried two mice. My Microsoft Natural Ergonomic Keyboard 4000 works fine on both switches across all machines.

It would seem it is something w/ my HP machine but what could it be? And how I can track down more details so I can reach out to the appropriate support people?

java – LIBGDX: Shoot a bullet using mouse position

I want to shoot a bullet towards my mouse position but I think that my math is probably wrong since the position the bullets travel to isn’t the right one.
Here’s my code

Vector2 bulletDirection = new Vector2(screenX - player.getX(), Gdx.graphics.getHeight() - (player.getY() - screenY)).nor();
bullet.setPosiion(player.getX(), player.getY());
bullet.translate(bulletDirection.x * flightSpeed, bulletDirection.y * flightSpeed);

Can you tell me what I’m doing wrong? The “bullet” object is my current bullet sprite

directx11 – DirectX 11 Mouse Picking Problem

I’m trying to do mouse picking and actually it works but when I scale the object and click that point on the image it picks wrong one, this happens only after scaling an object and I’m sure matrices are correct, any idea?

enter image description here

    DirectX::XMFLOAT4X4 projection;
    DirectX::XMStoreFloat4x4(&projection, Graphics::projectionMatrix);

    float viewX = ((2.0f * Input::GetMouseX()) / MainWindow::GetDisplayResolution().width - 1.0f) / projection(0,0);
    float viewY = (1.0f - (2.0f * Input::GetMouseY()) / MainWindow::GetDisplayResolution().height) / projection(1,1);

    DirectX::XMMATRIX inverseMV = DirectX::XMMatrixInverse(nullptr,DirectX::XMMatrixTranspose(entity->Renderer_->MV_Matrix)); //MV is column order

    DirectX::XMVECTOR rayOrigin = DirectX::XMVector3TransformCoord(DirectX::XMVectorSet(0.0f,0.0f,0.0f,1.0f), inverseMV);
    DirectX::XMVECTOR rayDirection = DirectX::XMVector3Normalize(DirectX::XMVector3TransformNormal(DirectX::XMVectorSet(viewX, viewY, 1.0f, 0.0f), inverseMV));
    
    for (const auto& subMesh : entity->Renderer_->mesh->GetSubMeshes())
    {
        float distance = 0.0f;
        if (subMesh.AABB.Intersects(rayOrigin, rayDirection, distance))
        {
            for (unsigned int i = 0; i < subMesh.GetIndexCount(); i += 3)
            {
                DirectX::XMVECTOR p1 = DirectX::XMLoadFloat3(&subMesh.positions(subMesh.indices(i)));
                DirectX::XMVECTOR p2 = DirectX::XMLoadFloat3(&subMesh.positions(subMesh.indices(i + 1)));
                DirectX::XMVECTOR p3 = DirectX::XMLoadFloat3(&subMesh.positions(subMesh.indices(i + 2)));

                if (DirectX::TriangleTests::Intersects(rayOrigin, rayDirection, p1, p2, p3, distance) && distance < minDistance)
                {
                    minDistance = distance;
                    *pickedEntity = entity;
                }
            }
        }
    }