Author Topic: _SENDKEY problem.  (Read 2686 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
_SENDKEY problem.
« on: August 29, 2021, 01:05:13 pm »
This worked in Paintdotnet for "Save As"
 
Code: QB64: [Select]
  1.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  2.  
  3. CONST KEYEVENTF_KEYUP = &H2
  4. CONST VK_SHIFT = &H10 'Shift key
  5. CONST VK_CTRL = &H11 ' Ctrl key
  6.  
  7. ' Sequence for Ctrl+Shift+S for "SAVE AS" in apps like Paintdotnet and Notepad, etc.
  8. SENDKEYS VK_CTRL, 0, 0, 0
  9. SENDKEYS VK_SHIFT, 0, 0, 0
  10. SENDKEYS &H53, 0, 0, 0 ' S key
  11.  
  12. SENDKEYS &H53, 0, KEYEVENTF_KEYUP, 0
  13. SENDKEYS VK_SHIFT, 0, KEYEVENTF_KEYUP, 0
  14. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0
  15.  

Now what I can't get working is the Ctrl + F for "FIND" in Notepad, as shown below. BTW, yes, I do set the focus back to Notepad, using a _SCREENCLICK statement, which works, so this isn't a focus issue. Do I have the keycode incorrect? I mean by itself, &H46 will print the lowercase letter "f" to the screen, but when I combine it with what I believe is the proper &H11, for the ctrl key, nothing happens.

Code: QB64: [Select]
  1.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  2.  
  3. CONST KEYEVENTF_KEYUP = &H2
  4. CONST VK_SHIFT = &H10 'Shift key
  5. CONST VK_CTRL = &H11 ' Ctrl key
  6.  
  7. SENDKEYS VK_CTRL, 0, 0, 0 ' Ctrl
  8. SENDKEYS &H46, 0, 0, 0 ' f
  9.  
  10. SENDKEYS &H46, 0, KEYEVENTF_KEYUP, 0 ' Release f
  11. SENDKEYS VK_CTRL, 0, KEYEVENTF_KEYUP, 0 ' Release Ctrl
  12.  

That code will not open the "Find" popup in Notepad, as intended.

Any ideas what's not coded correctly here? If needed, I could post a SHELL and focus to Notepad, but a user would have to place Notepad so it opens approximately 3/4 of the screen size and the title bar would have to be at the top margin for _SCREENCLICK to focus it.

Pete


Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: _SENDKEY problem.
« Reply #1 on: August 29, 2021, 01:25:22 pm »
RESOLVED!

The code is fine. It may have been a problem with mixing _HIDE with _DONTWAIT when opening up the Notepad doc! I removed _HIDE and it now works. Go figure. Oh, if anyone tries this, please be aware you need to use a notepad doc with something in it. Don't just use a blank notepad, as I don't believe a manual Ctrl + F even works if there is nothing to find. In my case, I'm using it to search rather large databases, so making a ctrl + f , a paste of the serch and an enter via QB64 greatly speeds up the process.

Oh well, it's a good thing Pete came by, to figure this our. :D

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/