Giter VIP home page Giter VIP logo

Comments (12)

emoon avatar emoon commented on June 9, 2024 1

0.24 has been released and it includes this fix

from rust_minifb.

emoon avatar emoon commented on June 9, 2024

Not that I know of. If you do if window.is_key_down(Key::F10) { ... } in the window update loop (not callback) does that work as expected?

from rust_minifb.

loudjanilef avatar loudjanilef commented on June 9, 2024

Thank you for your answer
I tested your snippet with F9 and F10 and it works properly with F9 but not with F10.
I guess it does not comes from my keyboard as I reproduced this problem on two different computers (and so keyboards)

from rust_minifb.

emoon avatar emoon commented on June 9, 2024

I see. Which OS do you see this behavior on?

from rust_minifb.

loudjanilef avatar loudjanilef commented on June 9, 2024

I am running on windows 10 for both computers

from rust_minifb.

emoon avatar emoon commented on June 9, 2024

Alright. I will try on a Windows 10 machine here and see if the same thing happens for me.

from rust_minifb.

emoon avatar emoon commented on June 9, 2024

I get the same behavior here. When searching around I found this https://gamedev.net/forums/topic/644254-pressing-f10-pause-main-loop/5069517 and the suggestion here is to

switch(message)
	{
	case WM_SYSCOMMAND:
        {
            switch (wParam)
            {    
                // Disables System Menu (F10 Key)       
                case SC_KEYMENU:
                {
                    return 0;
                }//SC_KEYMENU
                break;

So I tried to add this code inside the minifb code:

        winuser::WM_SYSCOMMAND => {
            if wparam == winuser::SC_KEYMENU {
                return 0;
            }
        }

And that indeed gets rid of the "freezing" of the application, but it still don't get the F10 key sent to the application so something more needs to be changed.

from rust_minifb.

emoon avatar emoon commented on June 9, 2024

Ok, I have a potential fix if you want to test it locally

index 2ea0511..fc11588 100644
--- a/src/os/windows/mod.rs
+++ b/src/os/windows/mod.rs
@@ -207,6 +207,12 @@ unsafe extern "system" fn wnd_proc(
     let mut wnd: &mut Window = mem::transmute(user_data);

     match msg {
+        winuser::WM_SYSCOMMAND => {
+            if wparam == winuser::SC_KEYMENU {
+                return 0;
+            }
+        }
+
         winuser::WM_MOUSEWHEEL => {
             let scroll = ((((wparam as u32) >> 16) & 0xffff) as i16) as f32 * 0.1;
             wnd.mouse.scroll = scroll;
@@ -269,6 +275,11 @@ unsafe extern "system" fn wnd_proc(
             return 0;
         }

+        winuser::WM_SYSKEYUP => {
+            update_key_state(wnd, (lparam as u32) >> 16, false);
+            return 0;
+        }
+
         winuser::WM_COMMAND => {
             if lparam == 0 {
                 wnd.accel_key = (wparam & 0xffff) as usize;

from rust_minifb.

loudjanilef avatar loudjanilef commented on June 9, 2024

I tried this and did it seem to work, although i only receive the state false events.
With this patch I receive both :

index 2ea0511..1aec629 100644
--- a/src/os/windows/mod.rs
+++ b/src/os/windows/mod.rs
@@ -207,6 +207,12 @@ unsafe extern "system" fn wnd_proc(
     let mut wnd: &mut Window = mem::transmute(user_data);
 
     match msg {
+        winuser::WM_SYSCOMMAND => {
+            if wparam == winuser::SC_KEYMENU {
+                return 0;
+            }
+        }
+
         winuser::WM_MOUSEWHEEL => {
             let scroll = ((((wparam as u32) >> 16) & 0xffff) as i16) as f32 * 0.1;
             wnd.mouse.scroll = scroll;
@@ -224,6 +230,11 @@ unsafe extern "system" fn wnd_proc(
             return 0;
         }
 
+        winuser::WM_SYSKEYDOWN => {
+            update_key_state(wnd, (lparam as u32) >> 16, true);
+            return 0;
+        }
+
         winuser::WM_CHAR => {
             char_down(wnd, wparam as u32);
         }
@@ -269,6 +280,11 @@ unsafe extern "system" fn wnd_proc(
             return 0;
         }
 
+        winuser::WM_SYSKEYUP => {
+            update_key_state(wnd, (lparam as u32) >> 16, false);
+            return 0;
+        }
+
         winuser::WM_COMMAND => {
             if lparam == 0 {
                 wnd.accel_key = (wparam & 0xffff) as usize;

from rust_minifb.

emoon avatar emoon commented on June 9, 2024

Cool. I will make the change and try to release a new version with the fix today.

from rust_minifb.

loudjanilef avatar loudjanilef commented on June 9, 2024

Thanks for your fast answers
The lib is very helpful

from rust_minifb.

emoon avatar emoon commented on June 9, 2024

Great to hear :)

from rust_minifb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.