AndersMalmgren / FreePIE

Programmable Input Emulator
642 stars 144 forks source link

Freepie equivalent of swallowkeys from glovepie #139

Open drowhunter opened 6 years ago

drowhunter commented 6 years ago

since freepie is the spiritual successor to glovepie. There is a feature that i sorely miss. The ability to remap keyboard keys and block the input .

for example when pressing Key.B it would send key.W but "key.B" would not go through, just "key.W"

does anyone know how to accomplish this? I tried using using a low level hook but not sure how you would do it with c#

AndersMalmgren commented 6 years ago

I looked into this a long time ago, didn't find a working solution back then. But if glovepie can do it, it's possible :)

drowhunter commented 6 years ago

i looked into it a while ago myself. i kind of had it working the issue was the Low level keyboard hook works by intercepting the key using standard windows messaing . which works as long as the application is reading the keyboard using directinput.

however if the application reads the keyboard directly using rawinput then it bypasses that altogether

truth is this may have been an issue in glovepie as well i never actually checked to see if swallowkeys worked in games that use rawinput. i might try that tonight

AndersMalmgren commented 6 years ago

Cool, how did it go?

drowhunter commented 6 years ago

oh, i havent had time to investigate yet. I'll find a copy of glovepie and try it in rawinput games to see if swallowkeys is actually able to block the keys. If not , i guess the solution i had come up with was promising .

maybe ill dig up the old code i wrote to see if theres a way to get it working..i was thinking about maybe a rawinput version of the keyboard plugin.

as i said the games that failed blocking keys were games like streetfighter 4/5 and mame because they read the keyboard directly

Frenchy62620 commented 6 years ago

the hook keyboard is done!! file to install in FeePIE folder (its the hooker process) InputTrackingExample.zip

so the solution is to create an another little process which hooks keyboard (and mouse if you adapt coding). Inside FreePie, you just see the branch Hooking i have forked. I give you an example of script but the coding is easy to understand. I am using memory shared to dialog between the 2 process

Hooker.keyboard.swallow(["alpha","-ABCDEF"] hook all alph keys except A to F

the key sended byt setPressed bypasses always the Hook

just E and F key Hooked

if starting: Hooker.keyboard.swallow(["EF"])

if speech.said("start hook"): Hooker.keyboard.setHook(True)

if speech.said("stop hook"): Hooker.keyboard.setHook(False)

if Keyboard.IsPressed(Key.F): speech.say("Key F")

if Hooker.keyboard.Ispressed(Key.E): keyboard.setPressed(Key.D)

here its the project inputTracking done in VS 2017 but totally compatible in VS 2015 InputTrackingProject.zip

AndersMalmgren commented 6 years ago

Nice job, You dont need it to be a seperate exe you can spawn and manage processes from within a ,NET app. But you need to communicate with it through shared memory just like you do.

hmmm.. Hooker, I think we should find a better name :P

Frenchy62620 commented 6 years ago

Hi anders.. its just a test, i have tried to create Thread and launch, but no result i think the Hook has an limited effect within child thread what are you thinking about to spawn and manage process within .net app?