MCPcopy Create free account
hub / github.com/TASEmulators/fceux / input_get

Function input_get

src/lua-engine.cpp:2555–2742  ·  view source on GitHub ↗

adelikat - the code for the keys is copied directly from GENS. Props to nitsuja the code for the mouse is simply the same code from zapper.get input.get() takes no input, returns a lua table of entries representing the current input state, independent of the joypad buttons the emulated game thinks are pressed for example: if the user is holding the W key and the left mouse button and has the mous

Source from the content-addressed store, hash-verified

2553// and has the mouse at the bottom-right corner of the game screen,
2554// then this would return {W=true, leftclick=true, xmouse=319, ymouse=223}
2555static int input_get(lua_State *L) {
2556 lua_newtable(L);
2557
2558#ifdef __WIN_DRIVER__
2559 // keyboard and mouse button status
2560 {
2561 extern int EnableBackgroundInput;
2562 unsigned char keys [256];
2563 if(!EnableBackgroundInput)
2564 {
2565 if(GetKeyboardState(keys))
2566 {
2567 for(int i = 1; i < 255; i++)
2568 {
2569 int mask = (i == VK_CAPITAL || i == VK_NUMLOCK || i == VK_SCROLL) ? 0x01 : 0x80;
2570 if(keys[i] & mask)
2571 {
2572 //ignore mouse buttons if the main window isn't focused
2573 if(i==1 || i==2)
2574 if(GetForegroundWindow()!=hAppWnd)
2575 continue;
2576
2577 const char* name = s_keyToName[i];
2578 if(name)
2579 {
2580 lua_pushboolean(L, true);
2581 lua_setfield(L, -2, name);
2582 }
2583 }
2584 }
2585 }
2586 }
2587 else // use a slightly different method that will detect background input:
2588 {
2589 for(int i = 1; i < 255; i++)
2590 {
2591 const char* name = s_keyToName[i];
2592 if(name)
2593 {
2594 int active;
2595
2596 //ignore mouse buttons if the main window isn't focused
2597 if(i==1 || i==2)
2598 if(GetForegroundWindow()!=hAppWnd)
2599 continue;
2600
2601 if(i == VK_CAPITAL || i == VK_NUMLOCK || i == VK_SCROLL)
2602 active = GetKeyState(i) & 0x01;
2603 else
2604 active = GetAsyncKeyState(i) & 0x8000;
2605 if(active)
2606 {
2607 lua_pushboolean(L, true);
2608 lua_setfield(L, -2, name);
2609 }
2610 }
2611 }
2612 }

Callers

nothing calls this directly

Calls 5

lua_pushbooleanFunction · 0.85
lua_setfieldFunction · 0.85
QtSDL_getKeyboardStateFunction · 0.85
lua_pushintegerFunction · 0.85
GetMouseDataFunction · 0.50

Tested by

no test coverage detected