Other members of his party echoed Mr. Trump’s sentiments. In a brief news conference, Speaker Paul D. Ryan said that “there may be some mental health issues with this shooting,” adding that it was not the time to jump to conclusions about tightening gun laws. In an address to a conference in Washington, Attorney General Jeff Sessions said law enforcement officers should look for warning signs in their communities.

“You and I know we cannot arrest everybody that somebody thinks is dangerous,” Mr. Sessions said. “But I think we can and we must do better. We owe it to every one of those kids crying outside their school yesterday and all those who never made it out of that school.”

As a presidential candidate, Mr. Trump enjoyed a mutually beneficial relationship with the National Rifle Association. The organization provided at least $30 million in support during his campaign. Receiving a hero’s welcome at the group’s annual convention last April, Mr. Trump said he would return the favor.

“Only one candidate in the general election came to speak to you, and that candidate is now the president of the United States, standing before you,” Mr. Trump said at the time. “You came through for me, and I am going to come through for you.”

But as with many issues, the president has had a complicated relationship with — and history of comments about — gun control.

Mr. Trump had a concealed weapon permit in New York when Rudolph W. Giuliani was mayor. It is not clear whether he maintained it. He also has spoken favorably about gun rights over the years. However, he has made clear that he is not a game hunter, as his two older sons are.

In 2000, as he considered running for president, he wrote in his book, “The America We Deserve,” that “I generally oppose gun control, but I support the ban on assault weapons and I also support a slightly longer waiting period to purchase a gun.”