|
-
Jun 24th, 2005, 01:54 PM
#1
Thread Starter
Member
keybd_event multiple keys
im using Call keybd_event(System.Windows.Forms.Keys.Tab, 0, 0, 0) function to call keyboard events,
but what if i want to press two keys at once? for instance, alt+tab
thanks
-
Jun 24th, 2005, 03:59 PM
#2
Thread Starter
Member
Re: keybd_event multiple keys
followup: ive been playing around with the process class and i am able to kill and start processes running in the background. but i have not been able to switch the active process similar to alt+tab
-
Jun 25th, 2005, 02:50 PM
#3
Re: keybd_event multiple keys
You can send an Alt + Tab like this.
VB Code:
Const VK_MENU = &H12
Const KEYEVENTF_KEYUP As Long = &H2
keybd_event(VK_MENU, 0, 0, 0) 'Alt down
keybd_event(System.Windows.Forms.Keys.Tab, 0, 0, 0) 'Tab down
keybd_event(System.Windows.Forms.Keys.Tab, 0, KEYEVENTF_KEYUP, 0) 'Tab up
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0) 'Alt up
You can send more tab presses to change the tab selection for which program to set as the active app.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 25th, 2005, 03:57 PM
#4
Thread Starter
Member
Re: keybd_event multiple keys
great thanks rob dog. i will try this when i get back to the office monday. one other quesiton. is there a way, instead of using alt+tab to switch applications. i am able to get a list of processes in the background. can i have vb tell explorer to make a certain process active, and then perform certain keystrokes using the code you just gave?
-
Jun 25th, 2005, 05:55 PM
#5
Re: keybd_event multiple keys
Yes there is. You need to use the Process object to get a list of runnig processes on your system and then you can terminate or
activate the one you want.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 25th, 2005, 06:38 PM
#6
Thread Starter
Member
Re: keybd_event multiple keys
yup i was able to kill processes using the kill function, but i wasnt able to find the activate function. do you know of it off hand. also, how would one find a list of all the functions? on the msdn website?
-
Jun 25th, 2005, 08:25 PM
#7
Re: keybd_event multiple keys
There is a function called AppActivate that will do the job. It is in the Microsoft.VisualBasic namespace, however, so will not be considered pure .NET. Also, it won't restore the app window if it is minimised.
You can also simulate the ALT+TAB key press with SendKeys.Send("%{TAB}").
-
Jun 26th, 2005, 10:45 AM
#8
Re: keybd_event multiple keys
Isnt the SendKeys method just a wrapper around the old vb6 SendKeys? I usually try to avoid it whenever I can since its unreliable.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 26th, 2005, 09:20 PM
#9
Re: keybd_event multiple keys
 Originally Posted by RobDog888
Isnt the SendKeys method just a wrapper around the old vb6 SendKeys? I usually try to avoid it whenever I can since its unreliable.
I really don't know what goes on under the hood of SendKeys, but the class is a memebr of the System.Windows.Forms namespace. If it was a wrapper for an old VB6 method then I would have expected it to be a member of Microsoft.VisualBasic. Remember that all members of any .NET Framework namespace (one that starts with System) are available to any .NET language, not just Visual Basic.
-
Jun 26th, 2005, 11:58 PM
#10
Re: keybd_event multiple keys
Either way, wouldnt the logic of SendKeys still be the same if it was in the .NET FW or MS VB Namespance? If it is then its still unreliable.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 27th, 2005, 12:22 AM
#11
Re: keybd_event multiple keys
Who's to say that the implementation of System.Windows.Forms.SendKeys.Send doesn't actually use the same method that you are proposing? I don't know that it does, but I also don't know that it doesn't. I've not heard anyone complain about it being unreliable, but that also doesn't mean that it's not. I just think that we should give a "pure .NET" method, that appears to do the job required, the benefit of the doubt before resorting to APIs.
-
Jun 27th, 2005, 12:25 AM
#12
Re: keybd_event multiple keys
Agreed but I have herd that you can write your APIs as managed code instead of unmanaged?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 27th, 2005, 01:12 AM
#13
Re: keybd_event multiple keys
 Originally Posted by RobDog888
Agreed but I have herd that you can write your APIs as managed code instead of unmanaged?
I could be wrong, but I would think that that would just mean wrapping your API calls in a class or module in a .NET assemby. You're still calling functions in Windows system libraries however you go about it.
By the way, nice badger! Minimally psychedelic.
-
Jun 27th, 2005, 10:15 AM
#14
Re: keybd_event multiple keys
Yes, but if the APIs are managed code then couldnt that be considered .NET code. 
Thanks, I gave a few members seizures so I had to change it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 27th, 2005, 07:17 PM
#15
Re: keybd_event multiple keys
I guess it depends what you consider to be .NET code. I could wrap calls to functions in Microsoft.VisualBasic in a .NET assembly but I know some members of this forum would be horrified to use it. I think that to be considered "pure .NET" code would have to use only in-built language features and objects and methods from the .NET Framework. Anything outside of that, I would think, has to be considered non-.NET. Not that that's a crime, and who knows how the objects and methods in the Framework are implemented anyway?
As a point of interest, note that registry access is achieved through the Microsoft.Win32 namespace. I know that Microsoft discourages using the registry in .NET apps, certainly to store data at least. Would you consider registry access to be non-.NET?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|