Page 1 of 1

SendInput_() disable SHIFT [Resolved]

Posted: Wed Jan 25, 2023 12:33 pm
by Kwai chang caine
Hello at all

Is it possible to write something in the parameters (wScan, dwFlags, etc ..) of SendInput_() for not use the SHIFT even if SHIFT is pressed or i must use a hook ?

Code: Select all

Structure INPUT_DATA

 type.l

 StructureUnion
  mi.MOUSEINPUT
  ki.KEYBDINPUT
  hi.HARDWAREINPUT
 EndStructureUnion

EndStructure

Delay(2000)
Define InputData.INPUT_DATA

Inputdata\type = #INPUT_KEYBOARD
inputdata\ki\wVk = 70 ; f
inputdata\ki\wScan = 34 ; f
SendInput_(1, InputData, SizeOf(INPUT_DATA))
Have a good day

Re: SendInput_() disable SHIFT

Posted: Wed Jan 25, 2023 1:27 pm
by RASHAD
Hi KCC
Why don't you forget about your new machine and come to normal :mrgreen:
Next is a perfect snippet By NM
Adapted by RASHAD
Adapt it for your needs

Code: Select all

Procedure SendInput(*txt) 

  *idata = AllocateMemory(SizeOf(INPUT)*2) 
  Protected *inputdata.INPUT, onekey.INPUT 
  
  *key.CHARACTER = *txt 
  
  While *key\c 
    
    ; Translate the character to its virtual key code
    ; and see if it requires SHIFT to be pressed
    
    key.w = VkKeyScan_(*key\c) 
    keyvalue = key & $FF 
    shift    = key >> 8 
    
    ; Press SHIFT if indicated
    
    If shift 
      RtlZeroMemory_(onekey,SizeOf(INPUT)) 
      With onekey 
        \type   = #INPUT_KEYBOARD 
        ;\ki\wVk = #VK_SHIFT                    
      EndWith 
      SendInput_(1, onekey, SizeOf(INPUT)) 
    EndIf 
    
    ; Press the character key down
    
    *inputdata = *idata 
    RtlZeroMemory_(*idata,SizeOf(INPUT)*2) 
    
    With *inputdata 
      \type   = #INPUT_KEYBOARD 
      \ki\wVk = keyvalue 
    EndWith 
    
    ; Release the character key
    
    *inputdata + SizeOf(INPUT) 
    
    With *inputdata 
      \type       = #INPUT_KEYBOARD 
      \ki\wVk     = keyvalue 
      \ki\dwFlags = #KEYEVENTF_KEYUP 
    EndWith 
    
    SendInput_(2, *idata, SizeOf(INPUT)) 

    ; Release the SHIFT key if we pressed it
    
    If shift 
      RtlZeroMemory_(onekey,SizeOf(INPUT)) 
      With onekey 
        \type       = #INPUT_KEYBOARD 
        \ki\wVk     = #VK_SHIFT 
        \ki\dwFlags = #KEYEVENTF_KEYUP          
      EndWith 
      SendInput_(1, onekey, SizeOf(INPUT)) 
    EndIf 
    
    ; Process next character if there is one
    
    *key+1 
  Wend      
EndProcedure 

RunProgram("notepad.exe") 
Delay(500) 
SendInput(@"Hello, This is a Message from PureBasic, Simply the finest programming tool in the world! ;)") 



Re: SendInput_() disable SHIFT

Posted: Wed Jan 25, 2023 1:32 pm
by infratec
As I have already written:

you have to send a press and a release of the shift key if you want a shift key.

All together you need then 4 keyboard inputs.


viewtopic.php?p=363502

Re: SendInput_() disable SHIFT

Posted: Wed Jan 25, 2023 6:25 pm
by Kwai chang caine
Hello at you two :D
MASTER RASHAD wrote:Why don't you forget about your new machine and come to normal
Because my PC normal is really to old....

Image

Like is owner :lol:

For the NM code, you have right... :shock: i have see this code, it is moreover in this code i have steal the
RtlZeroMemory_(InputData,SizeOf(INPUT_DATA))
RtlZeroMemory_(*keyInput,SizeOf(KBDLLHOOKSTRUCT))
When you have say to me : "KCC don't forget to flush the buffer" :wink:

But i have not thinking to replace all the SendInput_API function by this code :oops:

Nothing beats a good soup cooked by one of the better cook

Image

Rather than, by a do-it-yourselfer like KCC :lol:

Image
MASTER INFRATEC wrote:As I have already written:
you have to send a press and a release of the shift key if you want a shift key.
Don't worry, I always listened to you, because you give me so much valuable advice. 8)
That's why I opened this THREAD because I wanted to process the SHIFT and try to undo it. :wink:

For your link code, i have tried it there are 12 years :shock: It doesn't make us any younger :|
And about all this years...i have forget it :oops: but it is really complete 8)

@MY TWO HEROES
Again thanks for your precious and fasters helps during all this years
For me, this is also the big asset of PureBasic

This amazing and powerfulls MASTERS,
Image
always withdrawn, discreet but ready to teach knowledge
to their disciple
Kwaï chang caine 8)
(And all the other members obviously :wink: )

I love you
Your fan for the life
Kcc

Re: SendInput_() disable SHIFT

Posted: Wed Jan 25, 2023 6:55 pm
by normeus
I always wonder what KCC is programming. "A Chinese keyboard mapped to French?" Very interesting.
Just to make this post longer, some irrelevant info:

Code: Select all

; If the code you received  from the HOOK was 444
;     decimal to binary:     444 = 00000001 10111100
Debug 444 & $FF  ;  the keycode & "and"  255 to delete the shift key info (the higher 8 bits)  10111100 = 188

; depending on which "Shift State" is pressed:
; we get rid of the lower 8 bits by shifting ">> 8" then we & "and" to get only the bit we need 
Debug 444 >> 8 & $01  ;Either SHIFT key is pressed 
Debug 444 >> 8 & $02  ;Either CTRL key is pressed
Debug 444 >> 8 & $04  ;Either ALT key is pressed
Debug 444 >> 8 & $08  ;The Hankaku key is pressed

To get to the shift "bits" you see all the >> and the & $FF, Like I said, I just wanted to make the post bigger.

Anyway, since you know the scancode of the keys you want to change, my suggestion is to map the keyboard layout in the registry so you will not have to run your program in the background.

Code: Select all

; First, Add this Binary key to your registry
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout\Scancode Map
This binary key takes a specific hex format, the first 8 bytes are 0 then number of entries with terminating NULL ( remember lower byte first) then the scancode and the key to remap followed by NULL terminator.
For a better explanation, take a look at this site:
https://www.experts-exchange.com/articl ... eyond.html
EDIT:
this program will do the remap for you:
https://www.medo64.com/scancodemap/
Good luck,
Norm.

Re: SendInput_() disable SHIFT [Resolved]

Posted: Thu Jan 26, 2023 3:55 pm
by Kwai chang caine
Hello NORMEUS
MASTER wrote:Just to make this post longer, some irrelevant info:
Whaaaat !!!! never infos are irrelevant for KCC :D
KCC understand quickly, but you must explain to him numerous time :mrgreen:

Image

Your great explanation about bits is really interesting :shock:
I would try to understand after 20 reading :lol:
For me, all this << and & have always been hieroglyphs, and yet I would have liked so much to understand them :oops:

The link to this software is usefull too
I'm a little bit affraid to use this style of software, because i have used another one, before begin this code, and i have lost my Q, replaced by B and impossible to fix, because I did not know what the software had modified in the BDR
But thanks to you, i know where searched, if i did something stupid

I have three advantage to finish my code
1/ I learn a bit more about programming keyboard
2/ I can talk with several of my MASTERS friends (It's only an advantage for me :lol: )
3/ My code not modify the machine
4/ It works immediately without reboot

But it's sure, if that works, the BDR or Keyboard Layout like INFRATEC showed me is better solution...mainly for the my friends members of this forum :mrgreen:

I've really been happy to talk with you since so long
You have doubly right...much luck ....i would need :lol:
Again thanks and have a very good day

Re: SendInput_() disable SHIFT [Resolved]

Posted: Sat Jan 28, 2023 1:32 pm
by bgeraghty
Edit- Didn't see my post was a basically a duplicate.