logo
down
shadow

Retrieve process- or thread-id of global keypress using SetWindowsHookEx


Retrieve process- or thread-id of global keypress using SetWindowsHookEx

By : user4577070
Date : November 21 2020, 09:01 AM
may help you . I've got a specific application which I can find using
code :
public partial class Form1 : Form 
{
    [DllImport("user32.dll")]
    static extern IntPtr GetForegroundWindow();

    [DllImport("user32.dll")]
    static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);

    Process process;

    public Form1() 
    {
        process = Process.GetProcesses()
            .Where(x => x.ProcessName == "MyProcessName")
            .FirstOrDefault();

        //init global keypress as needed
    }

    void gkh_KeyUp(object sender, KeyEventArgs e)
    {
        IntPtr handle = GetForegroundWindow();
        uint processID = GetWindowThreadProcessId(handle, IntPtr.Zero);
        if (p2.Threads.OfType<ProcessThread>().Any(x => x.Id == Convert.ToInt32(processID)))
        {
            //keypress in MyProcessName
        }
        e.Handled = true;
    }


Share : facebook icon twitter icon
SetWindowsHookEx seems not working for me in C# (WH_KEYBOARD_LL, global)

SetWindowsHookEx seems not working for me in C# (WH_KEYBOARD_LL, global)


By : Joby
Date : March 29 2020, 07:55 AM
may help you . Is this a console app as Main(string[] args) and Console.ReadLine() would suggest?
if so then this might be the source of your problem
SetWindowsHookEx for WH_KEYBOARD (Global) Without using Dll?

SetWindowsHookEx for WH_KEYBOARD (Global) Without using Dll?


By : r.raj
Date : March 29 2020, 07:55 AM
I wish did fix the issue. This is not possible. The requirement is mentioned nearly in every place that talks about or give examples of global hooks on MSDN. Some examples:
Hook Procedures
datatables global search on keypress of enter key instead of any key keypress

datatables global search on keypress of enter key instead of any key keypress


By : sabbirjpi
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , What to do is to just unbind the keypress event handler that DataTables puts on the input box, and then add your own which will call fnFilter when the return key (keyCode 13) is detected.
code :
$("div.dataTables_filter input").keyup( function (e) {
    if (e.keyCode == 13) {
        oTable.fnFilter( this.value );
    }
} );
$(document).ready(function() {
   var oTable = $('#test').dataTable( {
                    "bPaginate": true,
                "bLengthChange": true,
                "bFilter": true,
                "bSort": true,
                "bInfo": true,
                    "bAutoWidth": true } );
   $('#test_filter input').unbind();
   $('#test_filter input').bind('keyup', function(e) {
       if(e.keyCode == 13) {
        oTable.fnFilter(this.value);   
    }
   });     
} );
How to process short keypress in the same time long keypress is performed?

How to process short keypress in the same time long keypress is performed?


By : M Post
Date : March 29 2020, 07:55 AM
this will help You will probably need to do some type of regular polling of the keyboard state to determine what controls to process. Unfortunately, Qt doesn't have a direct API for polling keyboard state. You'll have to keep track of which keys are down by maintaining a global map of keys that have had a keypress event but no keyrelease event. Then poll that map at a regular interval to get the list of keys that are pressed.
code :
pressed_keys = set()

def keyPressEvent(self, event):
    pressed_keys.add(event.key())

def keyReleaseEvent(self, event):
    pressed_keys.remove(event.key())
timer = QTimer()
timer.timeout.connect(self.update_game)
timer.start(100)  # Update rate

@QtCore.pyqtSlot()
def update_game(self):
    if Qt.Key_Space in pressed_keys:
        ...
    if Qt.Key_Up in pressed_keys:
        ...
cannot retrieve process id for global process name

cannot retrieve process id for global process name


By : Sggcore
Date : March 29 2020, 07:55 AM
Does that help You're using the argument in the :global.whereis_name/1 call. You don't need the {:global here and the name of the process is actually {:name, [1]}, so you need to call :global.whereis_name({:name, [1]}).
code :
defmodule GenServerDB.Worker do
  use GenServer

  def start_link(name) do
    GenServer.start_link(__MODULE__, :ok, [name: {:global, {:name, name}}])
  end

  def init(:ok) do
    {:ok, %{}}
  end
end

{:ok, pid} = Supervisor.start_link([Supervisor.Spec.worker(GenServerDB.Worker, [], [])], strategy: :simple_one_for_one)
Supervisor.start_child(pid, [[1]])
Supervisor.start_child(pid, [[2]])
Supervisor.start_child(pid, [[3]])
IO.inspect Supervisor.which_children(pid)
IO.inspect :global.whereis_name({:name, [1]})
[{:undefined, #PID<0.77.0>, :worker, [GenServerDB.Worker]},
 {:undefined, #PID<0.78.0>, :worker, [GenServerDB.Worker]},
 {:undefined, #PID<0.79.0>, :worker, [GenServerDB.Worker]}]
#PID<0.77.0>
Related Posts Related Posts :
  • How to get all ip address in LAN?
  • send value to controller using html.actionlink
  • Assembly "Microsoft.GeneratedCode" loaded
  • count the number of items in view in asp.net mvc
  • Shortcut Keys for Saving or Editing Record in C#
  • Very tricky/complex text formatting: How can I output a string[][] as a table?
  • Fill multiple textboxes after selecting a data from DropDownList in ASP.NET
  • How to launch an application after another is logged in in C#?
  • Unable to retrieve column values from one of the tables joined in a stored procedure?
  • Directories last file name display only
  • Why do I get a COMException when I try to initialize an Interop.Word.Application?
  • Finding subtotal for column in repeater control
  • dropdownlist item selected throw exception (stack empty)
  • How can I list IIS working processes programmatically?
  • How to access nested object from JSON with Json.NET in C#
  • OpenXml DataValidation set predefined List for columns
  • How to find recurring word groups in text with C#?
  • layout conrols to developp universal apps in windows 8.1 pro
  • Adding strings to a list via for loop xna
  • Using Vertex Arrays with OpenTK
  • Optimizing List<string>
  • C# Local variables
  • How can I merge the results of a group by Linq-to-XML query?
  • How to add Report in ASP.NET Project
  • C# How to display all instances of a loop in a label?
  • C# subscribe a function to System.Action that is subscribed to another System.Action: why does order matter?
  • Is there any negative effect to setting SqlCommand's CommandTimeout to a high value?
  • C# - TreeView Context Menu Out of Place when using keyboard
  • How to read stored procedure output and return it as list
  • How do you maintain changes made by VisualState triggers after setting another VisualState?
  • Should I be unit testing my bootstrapper and if so how?
  • using .SingleOrDefault() inside .Where() will raise the following exception:- System.NotSupportedException was unhandled
  • C# How would I fill a Form1 Parameter in the same seperate class
  • Access gridview row's data from LinkButton inside that row
  • Translating excel function to c# Math.pow not resulting in same values
  • Arranging Ten Inputted Numbers into Ascending and Descending order
  • AsEnumerable and Query Syntax
  • How can I defensively code against randomly referencing "Table 0" and null values?
  • Changing xaml code position based on screen size
  • Castle Windsor resolve ienumerable and name
  • Drawing multiple sprites with a for loop xna 4.0
  • For loop to Populate Textblocks
  • Visual Studio 2015: Create an Empty Project
  • What are .NET classes to replace the old MSXML2.ServerXMLHTTP?
  • Handle leak in .Net threads
  • Excel add-in ribbon click events bubbling
  • validation rule needed for only numbers to be entered
  • Parsing complex XML, no descendent elements exists when selecting a named element
  • Web Api - IEnumerable with complex type as param is null
  • Email address input validation
  • .Net AND operator Regular Expression using strings in a document
  • Windows phone 8.1 POST x-www-form-urlencoded not working
  • Is there any way to make my C# XMLManager work?
  • ASP.NET 5 Console Application (package) - How to create DBContext from connection string?
  • How to use form's function in other class C#
  • WPF Zebra EPL2 Printing issue
  • C# use reflection to capture exception throw
  • Convert strings in DataRow to double
  • Xml-Serialization is not working
  • HTML Agility Pack can't find classes with trailing spaces
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co